彩票的號碼有 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 }