1073 Scientific Notation
程序员文章站
2022-07-15 10:30:53
...
解题代码
#include<cstdio>
#include<cstring>
int main()
{
char str[10000];
scanf("%s", str);
if (str[0] == '-') printf("-");
int len = strlen(str);
int pol = 0;
while (str[pol] != 'E') { pol++; };
int num = pol - 3;
int a1, a2, E;
sscanf(str, "%d.%dE%d", &a1, &a2, &E);
if (E < 0) {
printf("0.");
for (int i = 0; i < -E - 1; i++) printf("0");
printf("%c", str[1]);
for (int i = 3; i < pol; i++) printf("%c", str[i]);
}
else if (num - E > 0) {
printf("%c", str[1]);
for (int i = 3; i < pol; i++) {
if (!(E--)) printf(".");
printf("%c", str[i]);
}
}
else {
printf("%c", str[1]);
for (int i = 3; i < pol; i++) printf("%c", str[i]);
for (int i = 0; i < E - num; i++) printf("0");
}
return 0;
}
测试结果
问题整理
1.字符串处理。
上一篇: 关于初识float的一点小感悟
下一篇: float
推荐阅读
-
evaluate-reverse-polish-notation
-
CF1073E Segment Sum
-
1073 Scientific Notation
-
PAT (Advanced Level) 1073 Scientific Notation(20 分)科学计数法
-
1073 Scientific Notation (20分)
-
*PAT_甲级_1073 Scientific Notation (20point(s)) (C++)【字符串处理/科学计数法】
-
A1073:Scientific Notation(20')
-
LeetCode-1073 负二进制数相加(思维题)
-
一文搞懂JSON(JavaScript Object Notation)
-
Ajax中数据传递的另一种模式 javascript Object Notation思想(JSON)