Hey everyone , I'm new at codeforces , but I don't know whether i'm doing something wrong in the code or it's something at codeforces that I don't know.
Here's the code for Codeforces Round #224 (Div. 2) prob 1 : 382A — Ksenia and Pan Scales ,
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int ch,l1,l2,l3;
ch=getchar();
string s1,s2,s3;
while(ch!='|') { s1+=(char)ch; ch=getchar(); }
ch=getchar();
while(ch!='\n') { s2+=(char)ch; ch=getchar(); }
ch=getchar();
while(ch!=EOF) { s3+=(char)ch; ch=getchar(); }
l1 = s1.length();
l2 = s2.length();
l3 = s3.length();
int s=0,i,tmp;
if(l1>l2){
if(l1<=l3+l2) {
tmp=l1-l2;
for(i = 0; i<tmp; i++) { s2+=s3.at(i); l2++; s++; }
}
else { cout << "Impossible" << endl; return 0; }
}else if(l1<l2){
tmp=l2-l1;
if(l2<=l3+l1) for(i = 0; i<tmp; i++) { s1+=s3.at(i); l1++; s++;}
else { cout << "Impossible" << endl ; return 0; }
}
if(l1==l2){
if((l3-s)%2!=0) { cout << "Impossible" << endl ; return 0; }
else {
for(i = s; i<l3 ; i++) { s1+=s3.at(i); i++; s2+=s3.at(i); }
}
}
cout << s1 << '|' << s2 << endl;
return 0;
}
I have checked against the test case at ideone and got right answer , but the result here was :
Test: #1, time: 0 ms., memory: 0 KB, exit code: 0, checker exit code: 1, verdict: WRONG_ANSWER
Input
AC|T
L
Output
Impossible
Answer
AC|TL
Checker Log
wrong answer The participant has not answer. But jury has.
I've been wondering as to what the last statement means.Help is always welcome. ThankYou,
Codeforces has Windows line-endings.
That means i went wrong at while(ch!='\n') { s2+=(char)ch; ch=getchar(); } ?
Well, I believe in C/C++ it doesn't matter and you won't get "\r"
Намучался с этим сам в одно время:o
You should use proper input methods instead of reading characters one by one:
You read last line up to EOF, but on CF last line contains "\n" too.
Yes as you said , I was scanning an extra char in the last line . Got AC now . Thank you .
In Baekjoon, it is called Mazwaetl(맞왜틀).