L1-062 幸运彩票

彩票的号码有 6 位数字,若一张彩票的前 3 位上的数之和等于后 3 位上的数之和,则称这张彩票是幸运的。本题就请你判断给定的彩票是不是幸运的。

输入格式:

输入在第一行中给出一个正整数 N(≤ 100)。随后 N 行,每行给出一张彩票的 6 位数字。

输出格式:

对每张彩票,如果它是幸运的,就在一行中输出 You are lucky!;否则输出 Wish you good luck.

输入样例:

2
233008
123456

输出样例:

You are lucky!
Wish you good luck.
 
思路:字符也是有ANSCI码的,没必要转化成数字再求和比较,直接比较就完事了......
 
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<map>
 6 #include<set>
 7 #include<vector>
 8 using namespace std;
 9 #define ll long long 
10 #define dd cout<<endl
11 const int inf=99999999;
12 const int mod=1e9+7;
13 const int maxn=1e5+7;
14 int main()
15 {
16     int T;
17     cin>>T;
18     string str;
19     while(T--)
20     {
21         cin>>str;
22         if((str[0]+str[1]+str[2])==(str[3]+str[4]+str[5]))
23             cout<<"You are lucky!"<<endl;
24         else
25             cout<<"Wish you good luck."<<endl;
26     }
27     return 0;
28 }

猜你喜欢

转载自www.cnblogs.com/xwl3109377858/p/10642007.html
今日推荐