1001. A+B Format (20):vector stack 简单运用
来源:互联网 发布:网络认证 编辑:程序博客网 时间:2024/05/01 01:51
提交两次···A
忘了测试 0 0 情况···
依旧是考虑不全,还没有养成严谨的测试-调试习惯。
#include<iostream>#include<vector>#include<cmath>#include<stack>using namespace std;#define Max 1000000int main(){ int a, b; vector<int>V; stack<char>Stk;//用来存放带有","的输出序列 int sum; while( cin>>a>>b ) { V.clear(); sum=a+b; for( int i=sum, j=0; i!=0; i/=10, j++ ) V.push_back(i%10); if(sum==0)//差在这里了·· V.push_back(0); if(sum<0) cout<<"-"; for( int i=0, j=1; i<V.size(); i++, j++ ) { if( j%3==1 && j!=1 ) Stk.push(','); Stk.push(abs(V[i])+'0'); } while( !Stk.empty() ) { cout<<Stk.top(); Stk.pop(); } cout<<endl; } return 0;}
2015/8/26 version2.0——————————————————————————————————————————————
#include<iostream>#include<sstream>#include<vector>using namespace std;int main(){ int A, B; cin>>A>>B; stringstream Scin; int C=A+B; Scin<<C; string S; Scin>>S; vector<char>vec; for(int i=S.size()-1,j=0; i>=0; i--,j++) { if(j%3==0&&j!=0&&S[i]!='-') vec.push_back(','); vec.push_back(S[i]); } for(int i=vec.size()-1; i>=0; i--) cout<<vec[i]; cout<<endl; return 0;}
0 0
- 1001. A+B Format (20):vector stack 简单运用
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- Hadoop2.x Yarn作业提交(客户端)
- 多个返回 顶部的代码
- SAT阅读真题资料3
- 禁止锁屏和隐藏标题栏
- 四分位数(定义、位置、数值)
- 1001. A+B Format (20):vector stack 简单运用
- PHP收邮件receiveMail
- 《Java编程思想》学习笔记9——集合容器高级
- Android中自定义checkbox样式
- oracle创建用户及分区
- Android fill_parent、wrap_content和match_parent的区别
- Js中自定义(创建)Map以及对应方法
- UISegmentedControl的所有操作总结
- 字符之殇——CHAR WCHAR