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.me/contest/1676/problem/A
--> and this is my source code :
include
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.








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[0]+ .. +s[2] to s[3]+ .. + s[5], and have your answer. :)
Just want to point out: Of course you are right, also with your approach you don't need to initialise
sum1andsum2and 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.To help you helping yourself: find out about the debugging tools of your programming environment or use some temporary debug outputs. By inspecting
sum1andsum2you 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.
Keep it simple.
i think if u use % and / will be better for u
try it in paper it's easy idea
while (t--) {
str s; cin >> s;
if (((int)s[0] + (int)s[1] + (int)s[2]) == ((int)s[3] + (int)s[4] + (int)s[5]))
else
}