2011 Alibaba Programming Contest_1003_I'll play a trick on you

I'll play a trick on you

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2578    Accepted Submission(s): 731


Problem Description
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.
 

Input
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<=10100)
 

Output
For each case, output the number of case and the third integer.(as shown in the sample output)
 

Sample Input
  
  
3 99 72 45 27 39 18
 

Sample Output
  
  
Case 1: 27 Case 2: 18 Case 3: 21
Hint
If you have any idea to work out the ? and explain why but couldn't get Accepted , please email me (notonlysuccess@gmail.com), the first person will get 100RMB from me.
 

Author
NotOnlySuccess





这种题,各种yy。一开始估计很多人都想到“?”是15,即两数相减,但是这样最后应该是8而不是7 。所以果断是错误的yy。
我也经历了各种错误的yy,真是惭愧,最后还是去google了一下,找到这个看起来比较靠谱的yy,而这个也刚好是题目正确的yy:
99 = 9 + 9 = 18,72 = 7 + 2 = 9,18 + 9 = 27;
45 = 4 + 5 = 9,  27 = 2 + 7 = 9,9 + 9 = 18;
39 = 3 + 9 = 12,18 = 1 + 8 = 9,12 + 9 = 21;
       。。。。。。。
这样,最后的7也可以解释了:21 = 2 + 1 = 3,13 = 1 + 3 = 4,3 + 4 = 7
所以,“?”应该是12


代码:

#include <iostream>

#include <string>

using namespace std;



int main()

{

    int t;

    string sa, sb;

    cin >> t;

    for (int k = 1; k <= t; k++)

    {

        cin >> sa >> sb;

        int a = 0, b = 0;

        for (int i = 0; i < sa.size(); i++)

            a += sa[i] - '0';

        for (int i = 0; i < sb.size(); i++)

            b += sb[i] - '0';

        cout << "Case " << k << ": " << a+b << endl;

    }

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值