南阳oj 400 I'll play a trick on you (细节规律题 简单的字符串处理)

来源:互联网 发布:千牛卖家mac 编辑:程序博客网 时间:2024/06/05 23:48

I'll play a trick on you

时间限制:3000 ms  |  内存限制:65535 KB
难度:1
描述
Please look the picture carefully. Then I'll give you two integers and your task is output the third one.
Please never doubt the picture.

输入
The first line is a number T(1<=T<=30), represents the number of case. The next T blocks follow each indicates a case.
Each case contains two integers A,B (1<=B<=A<=10^100)
输出
For each case, output the number of case and the third integer.
样例输入
399 7245 2739 18
样例输出
271821
来源

2011 Alibaba Programming Contest

难点:

这道题很容易误认为就是直接的加减 但是注意到后面的7

思路:

实际上是 各个数位的数相加的和 加起来就是后来的数 

代码如下:

#include<stdio.h>#include<string.h> int main(){int n,i,s1,s2;char s[110],m[110];scanf("%d",&n);while(n--){s1=s2=0;scanf("%s%s",s,m);for(i=0;i<strlen(s);i++)s1+=(s[i]-'0');for(i=0;i<strlen(m);i++)s2+=(m[i]-'0');printf("%d\n",s1+s2);}return 0;}}

0 0
原创粉丝点击