PAT 甲级 A1060 (2019/02/22)

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 using namespace std;
 5 int n;
 6 string Deal(string S, int &e){
 7     int k = 0;    //s的下标
 8     while(S.length() > 0 && S[0] == ‘0‘){
 9         S.erase(S.begin());        //去掉S的前导0
10     }
11     if(S[0] == ‘.‘){        //若去掉前导0后是小数点,则说明S是小于1的学生
12         S.erase(S.begin());        //去掉小数点
13         while(S.length() > 0 && S[0] == ‘0‘){
14             S.erase(S.begin());    //去掉小数点后面非零位前的所有零
15             e--;    //每去掉一个零,指数e减1
16         }
17     }else{        //若去掉前导0后不是小数点,则找到后面的小数点删除
18         while(k < S.length() && S[k] != ‘.‘){    //寻找小数点
19             k++;
20             e++;    //只要不遇到小数点,就让指数e++
21         }
22         if(k < S.length()){    //while结束后k<S.length(),说明遇到了小数点
23             S.erase(S.begin() + k);        //删除小数点
24         }
25     }
26     if(S.length() == 0){
27         e = 0;        //如果去掉前导0后S的长度为0,则这个数为0
28     }
29     int num = 0;    //
30     k = 0;
31     string res;
32     while(num < n){        //只要精度还没到n
33         if(k < S.length())
34             res +=S[k++];    //只要还有数字,就加到res末尾
35         else
36             res += ‘0‘;        //否则res末尾添加0
37         num++;        //精度加1
38     }
39     return res;
40 }
41 int main(){
42     string S1, S2, S3, S4;
43     cin >> n >> S1 >> S2;
44     int e1 = 0, e2 = 0;        //e1 e2为S1 S2的指数
45     S3 = Deal(S1, e1);
46     S4 = Deal(S2, e2);
47     if(S3 == S4 && e1 == e2)        //若主体&指数相同,则输出“YES”
48         cout << "YES 0." << S3 << "*10^" << e1 << endl;
49     else            //这里对于YES,NO应该是字母全部大写
50         cout << "NO 0." << S3 << "*10^" << e1 << " 0." << S4 << "*10^" << e2 << endl;
51     return 0;
52 } 

原文地址:https://www.cnblogs.com/zjsaipplp/p/10419669.html

时间: 2024-08-30 05:53:20

PAT 甲级 A1060 (2019/02/22)的相关文章

PAT 甲级 A1100 (2019/02/22)

1 #include<cstdio> 2 #include<iostream> 3 #include<string> 4 #include<map> 5 using namespace std; 6 // [0,12]的火星文 7 string unitDigit[13] = { 8 "tret", "jan", "feb", "mar", "apr", &q

PAT 甲级 A1047 (2019/02/22)

#include<cstdio> #include<cstring> #include<algorithm> #include<vector> using namespace std; const int MAXN = 40010; const int MAXC = 2510; vector<int> Courses[MAXC]; char StuName[MAXN][5]; bool cmp(int a, int b){ //按照名字典序从小到

PAT 甲级 A1039 (2019/02/22)

#include<cstdio> #include<cstring> #include<algorithm> #include<vector> using namespace std; const int MAXN = 40010; const int MAXM = 26*26*26*10 + 1; vector<int> selectCourses[MAXM]; //vector数组,selectCourses[0] ~ selectCours

PAT 甲级 A1063 (2019/02/22)

#include<cstdio> #include<set> using namespace std; const int MAXN = 51; set<int> ST[MAXN]; //MAXN个集合 void compare(int x, int y){ //比较集合 ST[x] 和 ST[y] int DiffNumber = ST[y].size(), SameNumber = 0; //不同数的个数,相同数的个数 //遍历集合 ST[x] for(set<

PAT甲级【2019年3月考题】——A1158 TelefraudDetection【25】

Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, unsuspecting victims lose their entire life savings. To stop this crime, you are supposed to write a program to detect those suspects from a huge amount of phone c

PAT甲级1005 Spell It Right

题目:PAT甲级 1005 题解:水题.看到题目的第一时间就在想一位一位的mod,最后一加一转换就完事了.结果看到了N最大为10的100的次方,吓得我赶紧放弃这个想法... 发现碰到这种情况用字符串十分好用,这道题应该考察的就是这一点.大致思路就是把数字的每一位放到字符串中,然后通过ASCII码得到每一位的相加结果num,然后把num一位一位的放到stack中,使用stack是因为它先进先出的特性,最后输出就行了. 代码: 1 #include<cstdio> 2 #include<qu

【谜客帝国】第147届月思主擂谜会(2019.02.15)

 [谜客帝国]第147届月思主擂谜会(2019.02.15) 主持计分:东东 1.“人在中天日月间”(9笔字)春/月思 [注:面出陈孚<开平即事二首>,“势超大地山河上,-.”] 2. 玉漏声中烟气袅(3字法国奢侈品牌)YSL/月思 3. 双双相念初相爱(2字著名动漫人物)菜菜/月思 4.“数点燕云州外.雪霜威”(足球用语二,4+3)4132.451/月思 [注:面出余文<相见欢>,“登高望断龙旗,未曾归.几度中原北定,梦依稀.朔风乱,胡尘漫,掩斜晖.-.”] 5.“十载同心如一人

2019.6.22刷题统计

今日写统计如此早的原因是:下午回老家,无法刷题. 今天完成了普及组的100道题,但还未进入USACO. 通过数:9 通过题目编号:1061/1072/1085/1090/1103/1109/1113/1125/1132 排名:暂居第一 本网站开始时间:2019/6/15 15:02:09 结束时间:2019/6/22 12:58:30 共计6天21小时56分21秒. 完成题目(见图片): 通过普及组100题的练习,我发现了自己普及组的知识点仍然掌握不全面,还需要继续复习. 另外,已经完成了入门+

PAT甲级考前整理

终于在考前,刷完PAT甲级130道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种境界.PAT甲级题目总的说卡题目的比较多,卡测试点的比较少,有些题目还会有题意混淆,这点就不吐槽了吧.静下心来耍这130道题,其实磨练的是一种态度与手感,养成的是一种习惯.热爱AC没有错!! 130道题目主要的考点: 1.排序:快速排序,直接插入排序,希尔排序,分治排序,堆排序. 2.图论:拓扑排序.最短路径.深度搜索.广度搜索. 3.树:树的遍历.完全二叉树.AVL. 4.其他:并查集,模拟,哈希.背包.