pages:
- 1
AliJavaheri SAYS
This is my code and i get wrong answer in the judge system but this code isn't have any problem in my compiler
Plz help me . Tnx
int main(){
string str; ifstream infile; ofstream output; infile.open("Input.txt"); output.open("Output.txt");
while (infile >> str && str != "0"){
int sum = 0; for (int i = 0; i < str.length(); i++) { sum += str[i] - '0'; }
if (sum >= 10){ sum = (sum % 10) + (sum / 10);
} if (sum < 10){ output << sum << endl; }
}
infile.close(); output.close(); return 0; }
AMiR SAYS
You shouldn't use files to read/write input/output.
You have to use STDIN
and STDOUT
. cin
and cout
in c++
.
Look here for examples: https://sharecode.io/discussion/problemset/topic/175
AliJavaheri SAYS
Tnx you so much amir . problem solved
Login please!
In order to post something you must login first. You can use the form in the top of this page.