here is a question from codechef...
and here is my code ....
int main()
{
int t;
si(t);
while(t--)
{
string A,B;
cin.ignore();
getline(cin,A);
cin>>B;
for(int i=0;i<A.size();i++)
{
if(A[i]==' ')
continue;
A[i]= B[(A[i]-'A')];
}
cout<<A<<"\n";
}
return 0;
}
why am i getting wrong answer afterall i am getting everything correct on my local compiler....
Can first line of test has symbols as "." "," "!" ?
it would contain only Capital characters and spaces..
i have still not got the answer to my question... Why am i getting wrong answer????
What is
si(t)
in your code?its for scanf().. i have used a macro
define si(n) scanf("%d",&n)
It is bad to use
scanf
andcin
simultaneously.another question, even 2:
Where is definition of si(int &)?
Why don't use a magical thing (which is only known by me?) called "debugger"?
Try putting the cin.ignore() just before the while loop starts. Edit: I'm wrong, thought you had 2 getlines in there.
Not working still...
Maybe I missed something, but for input
your program returns
I tried this submission...
no, it returns THE SKY IS BLUE two times (for two test cases)
no, it's working as I described on my Windows XP, can someone else cofirm this ?
I tried on 2 PCs
same with
i have used online IDE as well as my own compiler in both cases it returns THE SKY IS BLUE SEE THIS
I just tried to help, I believe that when you replace your getline and strings with gets and char arrays, your solution will be accepted.
I'm not C/C++ guru, but ideone is using gcc (4.3.4), codechef is using g++ (4.3.2), I also used g++ and it didn't work. What compiler are you using?
gets
is not a good function, it is even not recommended as far as i know. It's better not to usescanf
andcin
at the same time.In addition, using
string::size()
in cycle condition is a bad practice because this function takes linear time.AFAIK
gets
is not recommended because it's not checking bounds, for programming contests it's ok I guess.You can tell us what to use rather than what not to use ;-)
I said that you should not combine
cin
andscanf
.In my opinion,
cin
andstring
more convenient thangets
and char arrays. I think that author of this topic thinks the same because he usescin
in his code.When I try this, still not working
for my input above I'm getting
Try this code with includes, it is working on VC++2005 on codeforces server.
size()
is OK,strlen
works in O(n)Ok, thanks.