今年是第一年浙大保研需要机试,半路出家完全没有底,看了晴神宝典大概十天以后,今年去考了PAT甲级,然后意料之中的失败了。第一道题解决完素数和最大公约数的问题以后只会用暴力,还没跳出来;第二道题一个测试点没过;第三道题可能题目最后一句话没看懂理解有点偏差,最后一个测试点没过;第四道题,题是看懂了,也觉得自己会写,写出来以后怎么输出还是不对?估计又是题目理解错了,orz,我这该死的英语理解。
总结来说还是自己太菜,离保研还有一段时间,今年的题目还没在网站公布,那就先刷刷其他题!嗯!就从命中注定的1073题开始吧!(其实是感觉自己大概能刷80题左右就浙大机试了,orz
1073传送门
Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [±][1-9].[0-9]+E[±][0-9]+ which means that the integer portion has exactly one digit, there is at least one digit in the fractional portion, and the number and its exponent’s signs are always provided even when they are positive.
Now given a real number A in scientific notation, you are supposed to print A in the conventional notation while keeping all the significant figures.
Input Specification:
Each input contains one test case. For each case, there is one line containing the real number A in scientific notation. The number is no more than 9999 bytes in length and the exponent’s absolute value is no more than 9999.
Output Specification:
For each test case, print in one line the input number A in the conventional notation, with all the significant figures kept, including trailing zeros.
Sample Input 1:
+1.23400E-03
Sample Output 1:
0.00123400
Sample Input 2:
-1.2E+10
Sample Output 2:
-12000000000
科学计数法的应用。将科学计数法表示的A用普通计数法表示出来(并保留特征数字)。其中科学计数法的整数部分只有一个数字,至少一个数字在小数部分
输入:A的数字长度不超过9999鸽字节,指数绝对值不超过9999.
输出:输出A的普通表示发的数,保留所有特征位包括尾部的0.
可以归类为字符串模拟吧?用最笨的方法做最稳的题hh
观察科学计数法的结构:
±1-9.0-9+E±0-9
第一次提交:2分的测试点出错,初步判断应该是特殊情况没有考虑到。
错误的点:
果然,因为当特征位大于指数时,我想当然的把尾部砍了,其实可以加小数,然后AC了。
放上AC的代码了,有点繁琐:
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<ctime>
#include<cmath>
#include<vector>
#include<cstdlib>
#include<set>
#include<queue>
#include<map>
#include<stack>
using namespace std;
int main() {
string str;
cin >> str;
int flag_i=0,flag_e=0;//判断整数,指数符号是否为'-'
if (str[0] == '-')flag_i = 1;
string sgn;//用来存放特征位
sgn = str[1];//整数部分
int i;
for (i = 3; i < str.length(); i++) {
if (str[i] == 'E')break;
sgn += str[i];
}
if (str[i + 1] == '-')flag_e = 1;//判断指数正负
int ex=0;//存放指数
for (int j = i+2; j < str.length(); j++) {
//cout << str[j] << ' ';
ex = ex * 10 + (str[j] - '0');
}
//cout << ex << endl;
if (flag_i == 1)cout << '-';//正负号
if (flag_e == 0) {
if (sgn.length() >= ex) {
for (int k = 0; k <= ex; k++) {
cout << sgn[k];
}
//第一次错的地方
for (int k = ex+1; k < sgn.length(); k++) {
if (k == ex+1)cout << '.';
cout << sgn[k];
}
cout << endl;
//第一次错的地方
}
else {
for (int k = 0; k < sgn.length(); k++) {
cout << sgn[k];
}
for (int k = 0; k < ex - sgn.length()+1; k++) {
cout << '0';
}
cout << endl;
}
}
else {
for (int k = 0; k < ex; k++) {
sgn.insert(sgn.begin(), '0');
}
sgn.insert(sgn.begin() + 1, '.');
for (int k = 0; k < sgn.length(); k++) {
cout << sgn[k];
}
cout << endl;
}
return 0;
}
菜鸡的PAT训练之路任重而道远,这也是我第一篇博客呀,希望在总结和与大家的交流中中进步呀!