nyoj 844 A+B Problem(V)
来源:互联网 发布:西澳大学 知乎 编辑:程序博客网 时间:2024/05/22 15:54
A+B Problem(V)
时间限制:1000 ms | 内存限制:65535 KB
难度:1
- 描述
- 做了A+B Problem之后,Yougth感觉太简单了,于是他想让你求出两个数反转后相加的值。帮帮他吧
- 输入
- 有多组测试数据。每组包括两个数m和n,数据保证int范围,当m和n同时为0是表示输入结束。
- 输出
- 输出反转后相加的结果。
- 样例输入
1234 1234125 1170 0
- 样例输出
86421232
看一道题看了好久就是没思路...烦死了。 随机选了一题,附上两种代码: 常规思路不用字符串:
#include<stdio.h>int f(int n){ int i; int sum=0; while(n) { i=n%10; sum=sum*10+i; n/=10; } return sum;}int main(){ int a,b; while(scanf("%d %d",&a,&b)&&(a!=0||b!=0)) { printf("%d\n",f(a)+f(b)); } return 0;}
字符串:
#include<stdio.h>#include<string.h>int main(){ int n,m,i,j,l1,l2; char a[20],b[20]; int a1[20],b1[20]; while(scanf("%s %s",a,b)&&(a[0]!='0'||b[0]!='0')) { l1=strlen(a); l2=strlen(b); memset(a1,0,sizeof(a1)); memset(b1,0,sizeof(b1)); for(i=0,j=0;i<l1;i++,j++) { a1[j]=a[i]-'0'; } for(i=0,j=0;i<l2;i++,j++) { b1[j]=b[i]-'0'; } for(i=0;i<20;i++) { a1[i]+=b1[i]; if(a1[i]>=10) { a1[i]-=10; a1[i+1]++; } } for(i=20-1;i>=0;i--) { if(a1[i]!=0) break; } for(;i>=0;i--) { printf("%d",a1[i]); } printf("\n"); } return 0;}
0 0
- nyoj-844-A+B Problem(V)
- NYOJ 844 A+B Problem(V)
- NYOJ 844 A+B Problem(V)
- NYOJ-844 A+B Problem(V)
- nyoj 844 A+B Problem(V)
- NYOJ 844 A+B Problem(V)
- NYOJ 844 A+B Problem(V)
- NYOJ 844 A+B Problem(V)
- NYOJ 844 A+B Problem(V)
- NYOJ 844 A+B Problem(V)
- 【NYOJ】[844]A+B Problem(V)
- NYOJ 844 A+B Problem(V)
- 【NYOJ-844】 A+B Problem(V)
- NYOJ-A+B Problem(V)
- NYOJ A+B Problem(V)
- nyoj A+B Problem(V)
- nyoj A+B Problem(V)
- nyoj题目844:A+B Problem(V)
- 《数据结构》 课程设计
- android图片加载防止OOM LruCache和DiskLruCache使用
- javascript原型
- 《现代操作系统4th》英文版阅读笔记 4.3.5章 实现文件共享
- Ubuntu14.04下安装ffmpeg
- nyoj 844 A+B Problem(V)
- 数据结构课程设计
- LeetCode Palindrome Number
- 克服跨洋网络延迟,使用Docker Hub Mirror加速Docker官方镜像下载
- 《数据结构课程设计》报告
- IP地址如何用十六进制表示
- 通过比喻来了解spring
- 内存池--高效实现
- 浅谈 my_strcmp() 函数