1073.Scientific Notation (20)
来源:互联网 发布:变性手术知乎 编辑:程序博客网 时间:2024/04/29 21:05
1073.Scientific Notation (20)
pat-al-1073
2017-01-27
- 乙级也有这题,所以不详细写了。这次稍微换了一点实现的方式
- 细心一点,坑见注释,但是估计每个人的坑都不一样,就自己写几个例子测一测吧
/** * pat-al-1073 * 2017-01-27 * C version * Author: fengLian_s */#include<stdio.h>#include<string.h>int main(){ freopen("in.txt", "r", stdin); char sign = getchar(); if(sign == '-') putchar('-'); char ch = getchar();//读小数点前的数 int a = ch - '0'; //printf("a = %d\n", a); getchar();//读掉'.' char str[10002];//读小数点后的数 int i = 0; while((ch = getchar()) != 'E') { str[i++] = ch; } str[i] = '\0'; //printf("str = %s\n", str); sign = getchar();//读指数的符号 //printf("sign of e = %c\n", sign); int e; scanf("%d", &e);//读指数 //printf("e = %d\n", e); if(e == 0)//坑:指数为0的时候特殊处理一下,不然会出错 { printf("%d.%s\n", a, str); return 0; } if(sign == '-') { printf("0."); for(int i = 1;i < e;i++) putchar('0'); printf("%d%s", a, str); } else { printf("%d", a); if(strlen(str) <= e) { printf("%s", str); for(int i = 0;i < e-strlen(str);i++) putchar('0'); } else { int i; for(i = 0;i < e;i++)//出错:一开始写成strlen(str)-e了…… putchar(str[i]); if(i < strlen(str)) putchar('.'); for(;i < strlen(str);i++) putchar(str[i]); } } putchar('\n');}
-FIN-
0 0
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 新年重磅! flowchart可视化流程图编程语言发布
- Java结构型设计模式-适配器(一)
- 伸展树(排列变换,uva 11922)
- 字符串空格处理
- Gradle出现Could not create task of type 'DependencyManagementReportTask'
- 1073.Scientific Notation (20)
- gradle连接shadowsock代理
- java NIO socket编程简介
- 二项堆 数据结构说解
- 连接文件
- 写给2017年的自己
- Tcp C/S架构实现聊天室(链表管理在线用户)(服务器)
- SGD的batch size多大是合适的?
- 过河问题