This is very weird for me.
The problem code is : FLOW004
problem link is : FLOW004 Problem - CodeChef
This code :
#include
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
int n,l,f;
cin>>n;
l=n%10;
while(n != 0)
{
f = n%10;
n=n/10;
}
cout<<f+l<<endl;
}
return 0;
}
Works perfectly and gets accepted on the submission.
But below code :
#include
using namespace std;
int main() {
// your code goes here
int t ;
cin >> t;
while(t–){
int n;
cin >> n;
int last_digit = n%10;
while(n>10){
n = n/10;
}
cout << n + last_digit << endl;
}
return 0;
}
is NOT accepted.
I means both programs give the same result so why does one gets accepted and other not ?