490 - Rotating Sentences

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

Moderator: Board moderators

490 - Rotating Sentences

Postby @ce » Tue May 29, 2012 5:02 pm

Getting correct for sample input but getting WA...plzz help me find the error in my code.

Code: Select all
AC
Last edited by @ce on Sun May 26, 2013 10:27 am, edited 2 times in total.
-@ce
User avatar
@ce
Learning poster
 
Posts: 66
Joined: Mon May 28, 2012 8:46 am
Location: Ranchi, India

Re: 490 - Rotating Sentences

Postby brianfry713 » Fri Jun 01, 2012 12:33 am

Try the sample I/O again.
brianfry713
Guru
 
Posts: 1870
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentences

Postby @ce » Fri Jun 01, 2012 10:21 am

I am still not finding anything wrong :(

Input
Code: Select all
Rene Decartes once said,
"I think, therefore I am."


Output generated by my code:-
Code: Select all
"R
Ie
 n
te
h
iD
ne
kc
,a
 r
tt
he
es
r
eo
fn
oc
re
e
 s
Ia
 i
ad
m,
.
"
Last edited by @ce on Tue Jun 19, 2012 8:20 am, edited 1 time in total.
-@ce
User avatar
@ce
Learning poster
 
Posts: 66
Joined: Mon May 28, 2012 8:46 am
Location: Ranchi, India

Re: 490 - Rotating Sentences

Postby brianfry713 » Fri Jun 01, 2012 11:42 pm

Your problem might be that arr is uninitialized and then you check it for '\0'. On my machine (and possibly the judge's) that gave different results.
brianfry713
Guru
 
Posts: 1870
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentences

Postby @ce » Sun Jun 03, 2012 3:11 pm

@brianfry....java version of the same code is also giving WA...neither i could correct the above C++ code

Code: Select all
AC
Last edited by @ce on Sun May 26, 2013 10:28 am, edited 2 times in total.
-@ce
User avatar
@ce
Learning poster
 
Posts: 66
Joined: Mon May 28, 2012 8:46 am
Location: Ranchi, India

Re: 490 - Rotating Sentences

Postby brianfry713 » Mon Jun 04, 2012 10:49 pm

For your JAVA code, try the input:
Code: Select all
"I think, therefore I am."
Rene Decartes once said,


Output should be:
Code: Select all
R"
eI
n
et
 h
Di
en
ck
a,
r
tt
eh
se
 r
oe
nf
co
er
 e
s
aI
i
da
,m
 .
 "


There should be a newline at the end of the last line.
brianfry713
Guru
 
Posts: 1870
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentences

Postby xtine.m » Thu Jun 14, 2012 4:38 am

I'm having the same problem. I can't seem to see what's wrong with my output. Please help.

Code: Select all
#include <stdio.h>

int main(){
   char input[100][100] = {'\0'};
   int counter[100] = {0};
   char ch;
   int a = 0;
   int b = 0;
   int c = 0;
   int h;
   int i;
   int nos = 0;
   int high = 0;
   
   while (scanf ("%c", &ch) != EOF) {
      if (ch != '\n') {
         
         if (ch != '\t'){
            input[a][b] = ch;
            b++;
         }
         
      } else {
         counter[c] = b;
         
         if (high <= b) {
            high = b;
         }
         
         c++;
         b = 0;
         a++;
         input[a][b] = ch;
      }
      nos = a;
      
   }
   
   a = nos - 1;

   for (h = 0;h < high;) {
      for (i = a; i >= 0; i--) {
         printf("%c", input[i][h]);
      }
      printf("\n");
      h++;
   }
   return 0;
}

xtine.m
New poster
 
Posts: 6
Joined: Tue May 08, 2012 5:36 pm

Re: 490 - Rotating Sentences

Postby brianfry713 » Thu Jun 14, 2012 10:17 pm

For the sample input, you're printing null characters at the end of the last two lines.
brianfry713
Guru
 
Posts: 1870
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentences

Postby xtine.m » Fri Jun 22, 2012 11:55 am

brianfry713 wrote:For the sample input, you're printing null characters at the end of the last two lines.


hi! are you referring to the first sentence? since it has lesser characters it prints null characters. should it print a space? I edited my last code so it will print a space. so i added this code. but I still get a wrong answer.

Code: Select all
for (j = 0; j < c; j++) {
      temp = counter[j];
      if (high > temp) {
         min = high - temp;
         for (k = min; k >= 0 ;) {
         Tmin = temp+k;
         input[j][Tmin] = ' ';
         
         k--;
         }
      }
   }
xtine.m
New poster
 
Posts: 6
Joined: Tue May 08, 2012 5:36 pm

Re: 490 - Rotating Sentences

Postby brianfry713 » Fri Jun 22, 2012 11:34 pm

There should be spaces, not null characters. Post your full code.
brianfry713
Guru
 
Posts: 1870
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentences

Postby xtine.m » Mon Jun 25, 2012 3:43 am

Here's my full code:

Code: Select all
#include <stdio.h>

int main(){
   char input[100][100] = {'\0'};
   int counter[100] = {0};
   char ch;
   int a = 0;
   int b = 0;
   int c = 0;
   int h;
   int i;
   int j;
   int k;
   int temp;
   int min = 0;
   int Tmin = 0;
   int nos = 0;
   int high = 0;
   
   while (scanf ("%c", &ch) != EOF) {
      if (ch != '\n') {
         if (ch != '\t'){
            input[a][b] = ch;
            b++;
         }
      } else {
         counter[c] = b;
         
         if (high <= b) {
            high = b;
         }
         
         c++;
         b = 0;
         a++;
         input[a][b] = ch;
      }
      nos = a;
      
   }
   
   for (j = 0; j < c; j++) {
      temp = counter[j];
      if (high > temp) {
         min = high - temp;
         for (k = min; k >= 0 ;) {
         Tmin = temp+k;
         input[j][Tmin] = ' ';
         k--;
         }
      }
   }
   printf("\n");
   a = nos - 1;
   
   for (h = 0;h < high;) {
      for (i = a; i >= 0; i--) {
         printf("%d", input[i][h]);
      }
      printf("\n");
      h++;
   }
   return 0;
}
xtine.m
New poster
 
Posts: 6
Joined: Tue May 08, 2012 5:36 pm

Re: 490 - Rotating Sentences

Postby brianfry713 » Mon Jun 25, 2012 11:59 pm

Line 58 should be %c not %d.
brianfry713
Guru
 
Posts: 1870
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentences

Postby @ce » Tue Jun 26, 2012 2:23 pm

What's wrong??
My code :-
Code: Select all
AC
Last edited by @ce on Sun May 26, 2013 10:28 am, edited 1 time in total.
-@ce
User avatar
@ce
Learning poster
 
Posts: 66
Joined: Mon May 28, 2012 8:46 am
Location: Ranchi, India

Re: 490 - Rotating Sentences

Postby brianfry713 » Tue Jun 26, 2012 11:54 pm

You're printing an extra line at the end with two spaces.
brianfry713
Guru
 
Posts: 1870
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentences

Postby @ce » Wed Jun 27, 2012 7:39 pm

I tried this....still WA
My code :-
Code: Select all
AC
Last edited by @ce on Sun May 26, 2013 10:28 am, edited 1 time in total.
-@ce
User avatar
@ce
Learning poster
 
Posts: 66
Joined: Mon May 28, 2012 8:46 am
Location: Ranchi, India

Next

Return to Volume IV

Who is online

Users browsing this forum: No registered users and 0 guests