### Motaz_Husain's blog

By Motaz_Husain, 12 months ago, I Had A Problem solving the "lucky?" problem. And I Need just a little bit of help to solve it.

--> this is the link to the problem : https://codeforces.com/contest/1676/problem/A

--> and this is my source code :

# include

using namespace std;

int main(){ string num; int testCases,sum1,sum2;

cin>>testCases;

for(int k=0;k<=testCases-1;k++){

cin>>num;

for(int i=0;i<=2;i++){
sum1=sum1+num[i];
}//end for i - first 3-digits -

for(int j=3;j<=5;j++){
sum2=sum2+num[j];
}//end for j - Second 3-digits -

if(sum1==sum2){
cout<<"YES\n";
}//end if - sum1==sum2 -
else {
cout<<"NO\n";
}//end else

}//end for k-test cases-

return 0;

}//end main

So If Anybody can help I Would be super appreciative. Comments (10)
| Write comment?
 » Initialise sum1=sum2=0
 » As the constraints are very limited you can just compare the sum for first 3 to the last three as s+ .. +s to s+ .. + s, and have your answer. :)
•  » » Just want to point out: Of course you are right, also with your approach you don't need to initialise sum1 and sum2 and probably I would've done the same in a contest. But I really like, that Motaz_Husain used a for loop! This is very good form in my opinion and especially useful for someone who is starting into CP.
 » 12 months ago, # | ← Rev. 2 →   To help you helping yourself: find out about the debugging tools of your programming environment or use some temporary debug outputs. By inspecting sum1 and sum2 you would've found, that there are invalid values stored in them. Edit: Also please use the formating options CF provides.
•  » » can you tell me what is CF exactly ?
•  » » » Codeforces. The platform you are posting on.
•  » » » » alright, Thanks man I appreciate your advice.
 » 12 months ago, # | ← Rev. 2 →   Keep it simple. string s; cin >> s; cout << (s+s+s==s+s+s ? "YES" : "NO") << '\n'; 
 » 12 months ago, # | ← Rev. 2 →   i think if u use % and / will be better for u how to do itthree time{ sum1+=n%10 n/=10 } three time{ sum2+=n%10 n/=10 } and compere try it in paper it's easy idea
 » while (t--) {str s; cin >> s;if (((int)s + (int)s + (int)s) == ((int)s + (int)s + (int)s)) cout << "YES" << endl;else cout << "NO" << endl;}