My code is printing 192 for the input 100 (which is the desired result). But when I submit it on the online judge, it shows that the output of my program for the input 100 is 190. I copied and pasted the code in ideone.com and for input 100 I got result 192. I send it to my friend and on his PC the output is 190. But he also submitted the code onto ideone.com and got 192. What's the problem? Here's my code:
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main(){
lli in,ans = 0;
cin >> in;
if(in < 10)
cout << in << endl;
else{
lli digits = 0;
lli temp = in;
while(temp > 0){
digits++;
temp /= 10;
}
digits--;
while(in > 0){
//cout << "in: " << in << endl;
//cout << "digits: " << digits << endl;
ans += ((in - (pow(10,digits) - 1)) * (digits + 1));
in = in - (in - (pow(10,digits) - 1));
digits--;
if(in == 9){
ans+= 9;
break;
}
}
cout << ans << endl;
}
}
ideone link: http://ideone.com/zOvHzW
Why is this happening? I understand that it may be a compiler issue but what is really going on in here?