11946 - Code Number

All about problems in Volume CXIX. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

11946 - Code Number

Postby alfar01 » Tue Feb 14, 2012 3:35 pm

Why I got WA with my code?
Code: Select all
#include<stdio.h>
#include<string.h>
int main()
{
    freopen("11946.in","r",stdin);
   freopen("11946.out","w",stdout);
   int i,j,stat,part=1,flag1=1,flag2=1;
   char c[110][100],ans[]={"OIZEASGTBP"};
   scanf("%d\n",&stat);
   while(part<=stat){
      flag1?flag1=0:putchar('\n');
      for(i=0;;i++){gets(c[i]);if(c[i][0]=='\0')break;}
      for(i=0;c[i][0]!='\0';i++)
         for(j=0;c[i][j]!='\0';j++)
            if(c[i][j]>='0'&&c[i][j]<='9')
               c[i][j]=ans[c[i][j]-'0'];
      for(i=0;;i++){
         if(c[i][0]=='\0')break;
         flag2?flag2=0:putchar('\n');
         printf("%s",c[i]);
      }
      part++;
   }
   return 0;
}
alfar01
New poster
 
Posts: 2
Joined: Tue Feb 14, 2012 3:27 pm
Location: Tainan,Taiwan

Re: 11946 - Code Number

Postby brianfry713 » Wed Feb 15, 2012 12:14 am

You're reading and writing to files.
brianfry713
Guru
 
Posts: 1771
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11946 - Code Number

Postby alfar01 » Wed Feb 15, 2012 11:19 am

still get WA after removing the code of file reading
alfar01
New poster
 
Posts: 2
Joined: Tue Feb 14, 2012 3:27 pm
Location: Tainan,Taiwan

Re: 11946 - Code Number

Postby brianfry713 » Fri Feb 17, 2012 9:36 pm

For the sample input, you're not printing a newline at the end of the output.
brianfry713
Guru
 
Posts: 1771
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11946 - Code Number

Postby mahade hasan » Tue Jun 12, 2012 4:24 am

In this sample input
H3LL0 MY L0V3, 1 M H499Y 83C4U53 500N 1 W1LL 83 70 Y0UR 51D3.
7H15 71M3 W17H0U7 Y0U H45 833N 373RN4L. 1 1NV173 Y0U 70 7H3 200
0N3 70 533 7H3 238R42 4ND 60R1L42.

here 2==Z and 2==S somewhere in output
HELLO MY LOVE, I M HAPPY BECAUSE SOON I WILL BE TO YOUR SIDE.
THIS TIME WITHOUT YOU HAS BEEN ETERNAL. I INVITE YOU TO THE ZOO
ONE TO SEE THE ZEBRAS AND GORILAS.

it's confuse me..................
we r surrounded by happiness
need eyes to feel it!
User avatar
mahade hasan
Learning poster
 
Posts: 63
Joined: Thu Dec 15, 2011 3:08 pm

Re: 11946 - Code Number

Postby brianfry713 » Tue Jun 12, 2012 11:28 pm

5 should be S, 2 is Z. The sample I/O at the bottom of the problem statement is correct, the one in the middle is wrong.
Last edited by brianfry713 on Wed Jun 13, 2012 11:01 pm, edited 1 time in total.
brianfry713
Guru
 
Posts: 1771
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11946 - Code Number

Postby mahade hasan » Wed Jun 13, 2012 9:28 am

cut>>thanks for help!!
Last edited by mahade hasan on Thu Jun 14, 2012 8:24 am, edited 1 time in total.
we r surrounded by happiness
need eyes to feel it!
User avatar
mahade hasan
Learning poster
 
Posts: 63
Joined: Thu Dec 15, 2011 3:08 pm

Re: 11946 - Code Number WHY WA?PLZ HELP!

Postby Evan72 » Wed Jun 13, 2012 4:59 pm

Code: Select all
got AC
Last edited by Evan72 on Fri Jun 15, 2012 10:40 pm, edited 1 time in total.
Evan72
New poster
 
Posts: 11
Joined: Sat Apr 28, 2012 2:01 pm

Re: 11946 - Code Number

Postby brianfry713 » Wed Jun 13, 2012 11:02 pm

mahade hasan wrote:now i m dealing with WAWAWA!!


I had them switched, 5 should be S, 2 is Z.
brianfry713
Guru
 
Posts: 1771
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11946 - Code Number WHY WA?PLZ HELP!

Postby brianfry713 » Wed Jun 13, 2012 11:04 pm

Evan72, You need to copy the newlines.
brianfry713
Guru
 
Posts: 1771
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11946 - Code Number

Postby mahade hasan » Thu Jun 14, 2012 8:25 am

brianfry713 wrote:
mahade hasan wrote:now i m dealing with WAWAWA!!


I had them switched, 5 should be S, 2 is Z.


thanks for help.........
we r surrounded by happiness
need eyes to feel it!
User avatar
mahade hasan
Learning poster
 
Posts: 63
Joined: Thu Dec 15, 2011 3:08 pm

Re: 11946 - Code Number WHY WA?PLZ HELP!

Postby Evan72 » Fri Jun 15, 2012 10:39 pm

brianfry713 wrote:Evan72, You need to copy the newlines.

Thanx..got AC :)
Evan72
New poster
 
Posts: 11
Joined: Sat Apr 28, 2012 2:01 pm


Return to Volume CXIX

Who is online

Users browsing this forum: No registered users and 0 guests