wrong code
2015-09-11 23:17
260 查看
XDU 1060
#include <cstdio> #include <iostream> #include <stack> using namespace std; stack<int> m1; stack<int> m2; int main() { string s; while(cin >> s) { int len = s.size(), i; if(len == 1) { cout << "0.0"; int r = s[0] - '0'; r = r >= 5? 1: 0; cout << r << endl; } else if(len == 2) { cout << "0."; for(i = 0; i < len-1; i++) { m1.push(s[i]-'0'); } int r = s[i] - '0'; r >= 5? r = 1: r = 0; while(!m1.empty()) { r += m1.top(); m2.push(r%10); m1.pop(); r /= 10; } if(r) m2.push(r); if(m2.size() == 2) { cout << m2.top(); m2.pop(); cout << m2.top(); m2.pop(); } else { cout << 0 << m2.top(); m2.pop(); } cout << endl; } else if(len == 3) { cout << "0."; for(i = 0; i < len-1; i++) { m1.push(s[i]-'0'); } int r = s[i] - '0'; r >= 5? r = 1: r = 0; while(!m1.empty()) { r += m1.top(); m2.push(r%10); m1.pop(); r /= 10; } if(r) m2.push(r); cout << m2.top(); m2.pop(); cout << m2.top(); m2.pop(); cout << endl; } else { for(i = 0; i < len-1; i++) { m1.push(s[i]-'0'); } int r = s[i] - '0'; r >= 5? r = 1: r = 0; while(!m1.empty()) { r += m1.top(); m2.push(r%10); m1.pop(); r /= 10; } if(r) m2.push(r); int m_len = m2.size(); for(int i = 1; i <= m_len-2; i++) { cout << m2.top(); m2.pop(); } cout << '.'; while(!m2.empty()) { cout << m2.top(); m2.pop(); } cout << endl; } } }
相关文章推荐
- 数据库 之 入门篇
- 课后练习Javascript
- 远程调用方式概述
- wegweg
- 分解跨天的时间数据
- hdoj 1787 GCD Again【欧拉函数】
- colorPrimary colorPrimaryDark colorAccent
- ILMerge合并.Net程序集
- 面向对象 第五课 继承
- python学习笔记14 list列表数组
- JavaScript随笔(三):JS也有入口函数Main
- Sqlite3笔记
- LintCode Longest Common Substring
- Lecture1-3Applications of ML
- 线性回归与梯度下降算法
- const
- BZOJ 3601
- Source Insight设置
- IOS开发指南学习——XML解析
- MySQL表的四种分区类型