hdu 1002 A + B Problem II
来源:互联网 发布:马刺 霍尔特 知乎 编辑:程序博客网 时间:2024/05/17 13:11
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002
代码:
#include<iostream>#include<cstdio>#include<string.h>using namespace std;int main(){ char a[1005],b[1005]; int c[1005]; int N,cnt=0; while(scanf("%d",&N)!=EOF){ for(int i=1;i<=N;i++) { cnt=0; scanf("%s%s",a,b); int len1,len2,length,x1,x2,pos=0; len1=strlen(a); len2=strlen(b); while(len1>0&&len2>0){ x1=a[len1-1]-'0';//字符转换为数字 x2=b[len2-1]-'0'; //printf("x1 = %d x2 = %d\n",x1,x2); if(x1+x2+pos>=10){ c[cnt++]=x1+x2+pos-10; pos=1;//大于10用pos记下 //cout<<"1__"<<c[cnt-1]<<endl; } else{ c[cnt++]=x1+x2+pos; //cout<<"2__"<<c[cnt-1]<<endl; pos=0; } len1--; len2--; } if(len1>len2){ while(len1>0){ c[cnt++]=a[len1-1]-'0'+pos; //cout<<"3__"<<c[cnt-1]<<endl; pos=0; len1--; } } if(len1<len2) { while(len2>0){ c[cnt++]=pos+b[len2-1]-'0'; //cout<<"4__"<<c[cnt-1]<<endl; pos=0; len2--; } } if(len1==len2){ if(pos==1) c[cnt++]=1; } if(i==1){//任意两组数中间有空格 printf("Case %d:\n",i); printf("%s + %s = ",a,b); for(int k=cnt-1;k>=0;k--) printf("%d",c[k]); printf("\n"); } else { printf("\nCase %d:\n",i); printf("%s + %s = ",a,b); for(int k=cnt-1;k>=0;k--) printf("%d",c[k]); printf("\n"); } } } return 0;}
- HDU 1002 A + B Problem II
- HDU 1002A + B Problem II
- HDU 1002 - A + B Problem II
- HDU 1002 A + B Problem II
- HDU 1002 A + B Problem II
- HDU 1002 A + B Problem II
- HDU 1002 A + B Problem II
- HDU 1002 A + B Problem II
- hdu 1002 A+B Problem II
- HDU 1002 A + B Problem II
- hdu 1002 A + B Problem II
- HDU 1002 A + B Problem II (BigNums)
- hdu 1002 A + B Problem II
- hdu 1002 A + B Problem II
- hdu 1002 A + B Problem II
- HDU 1002 A + B Problem II
- HDU 1002 A + B Problem II
- Hdu---A + B Problem II---1002
- 分享2013年度超实用的15个原创Jquery插件
- fixed定位,兼容不同系列不同版本的浏览器(IE6.0)
- python cx_Oracle 5
- ggplot2系列:散点图qplot()
- Java语法糖的味道:泛型与类型擦除
- hdu 1002 A + B Problem II
- 悟透delphi 第十章 操作界面与操作逻辑
- hdu2175 两车追及或相遇问题
- cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
- ios 数据解析中值为Null和空的判断
- python cx_Oracle 6
- 为select添加样式
- Android AsyncTask源码分析
- document.all用法