PAT-A1028. List Sorting (25)(排序.)
2016-03-03 21:13
323 查看
水。
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <iomanip> #include <stdlib.h> using namespace std; #define MAX 10000+100 int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); char str[MAX], zhishu[MAX], xiaoshu[MAX]; memset(xiaoshu, '\0', sizeof(xiaoshu)); memset(zhishu, '\0', sizeof(zhishu)); int i = 0, j = 0, f = 0, k = 0; //k是小数中小数点后个位数 cin >> str; for (i = 1, j = 0; str[i] != 'E'; i++ ) { xiaoshu[j++] = str[i]; k++; if (str[i] == '.') k = 0; } i++; if (str[i] == '-') f = 1; for (i++, j = 0; str[i] != '\0'; i++) zhishu[j++] = str[i]; //指数为负数 if (f == 1) { if ('-' == str[0]) cout << "-"; if (atoi(zhishu) == 0) { for (i = 0; xiaoshu[i] != '\0'; i++) cout << xiaoshu[i]; } else { cout << "0."; for (i = 0; i < atoi(zhishu)-1; i++) cout << "0"; for (i = 0; xiaoshu[i] != '\0'; i++) if (xiaoshu[i] != '.') cout << xiaoshu[i]; } cout << endl; } //指数为正 else { if ('-' == str[0]) cout << "-"; if (atoi(zhishu) == 0) { for (i = 0; xiaoshu[i] != '\0'; i++) cout << xiaoshu[i]; } else { if ( k <= atoi(zhishu)) { for (i = 0; xiaoshu[i] != '\0'; i++) if (xiaoshu[i] != '.') cout << xiaoshu[i]; for(i = 0; i < atoi(zhishu)-k; i++) cout << "0"; } else { //yiwei for (i = 0; xiaoshu[i] != '\0'; i++) if (xiaoshu[i] == '.') break; int j = i; for (; i < j+atoi(zhishu); i++) xiaoshu[i] = xiaoshu[i+1]; xiaoshu[j+atoi(zhishu)] = '.'; cout << xiaoshu; } } cout << endl; } return 0; }
相关文章推荐
- Javascript面向对象与原型
- http协议三次握手
- [think in java]知识点学习
- 为什么匿名内部类只能访问其所在方法中的final类型的局部变量?
- lombok介绍
- .net自动获取token,
- bzoj4411 [Usaco2016 Feb] Load balancing
- 01背包问题最基础也是最重要的、
- golang捕获ctrl+c退出程序
- 快速排序
- Web开发学习之路--Eclipse+Tomcat+mysql之初体验
- Android布局的各种对齐问题
- set集中查找find
- PAT-1082. Read Number in Chinese (25)(模拟)
- Web开发学习之路--Eclipse+Tomcat+mysql之初体验
- C辗转相除法求最大公约数的实现
- BootStrap详解之(一)
- DSP 2812: 使用C++封装中断控制器PIE
- Android Studio 1.3及以上 NDK环境配置
- hdu 1272 小希的迷宫 解题报告