Source
Codeforces Round #362 (Div. 2)
My Solution
处理科学计算法的表达式
找到 " . " 和 " e " 的位置, 然后读清题目的条件就好了
a and b contain no leading zeros and d contains no trailing zeros (but may be equal to 0). Also, b can not be non-zero if a is zero.
#include
#include
#include
using namespace std;
typedef long long LL;
const int maxn = 2*1e2 + 8;
char val[maxn], line[maxn] = {};
int main()
{
#ifdef LOCAL
freopen("a.txt", "r", stdin);
//freopen("b.txt", "w", stdout);
int T = 4;
while(T--){
#endif // LOCAL
scanf("%s", val);
int len = strlen(val), b;
if(val[len-2] == 'e') b = val[len-1] - '0';
else if(val[len-3] == 'e') b = 10*(val[len-2] - '0') + val[len-1] - '0';
else b = 100;
int cnti;
for(int i = 1; i < len; i++){ if(b == 0) {cnti = 1; break;} if(val[i] != 'e'){ if(val[i+1] != 'e')val[i] = val[i+1]; else {val[i] = '.'; cnti = i; break;} b--; if(b == 0) {val[i+1] = '.'; cnti = i + 1; break;} } else break; } //printf("%sn %dn", val, cnti); bool _find = false, first = true; int ptr = 0; for(int i = len-1; i >= 0; i--){
if(val[i] == 'e') _find = true;
else if(_find){
if(first && val[i] == '0') ;
else{
if(val[i] != '.')ptr = i;
else ptr = i-1;
break;
}
}
}
for(int i = 0; i <= ptr; i++)
printf("%c", val[i]);
/*
bool first = true;
int cnt0 = 0;
for(int i = 0; i < len; i++){
if(val[i] != 'e'){
if(val[i] == '0' && first && i < cnti - 1) ;
else if(val[i] == '0' && first && i == cnti - 1) {printf("0"); first = false;}
else{
if(first) first = false;
if(!(val[i] == '.' && val[i+1] == 'e') && !(val[cnti] == '.' && val[cnti+1] == '0')){
if(val[i] == '0'){
cnt0++;
}
if(val[i] != '0'){
while(cnt0--) printf("0");
printf("%c", val[i]);
cnt0 = 0;
}
}
else if(val[cnti] == '.' && val[cnti+1] == '0'){
if(val[i] == '.') cnt0 = 1;
if(val[i] == '0'){
cnt0++;
}
if(val[i] != '0' && val[i] != '.'){
if(val[i-cnt0] == '.') {printf("."); cnt0--;}
while(cnt0--) printf("0");
printf("%c", val[i]);
val[]
cnt0 = 0;
}
}
}
}
else break;
}
*/
while(b) {printf("0"); b--;};
#ifdef LOCAL
printf("n");
}
#endif // LOCAL
return 0;
}
非特殊说明,本博所有文章均为博主原创,未经许可不得转载。
https://www.prolightsfxjh.com/
Thank you!
------from ProLightsfx
非特殊说明,本博所有文章均为博主原创,未经许可不得转载。
如经许可后转载,请注明出处:https://prolightsfxjh.com/article/codeforces-round-362-div-2-b-barnicle/
共有 0 条评论