490 - Rotating Sentences

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

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentences why? WA please help me

Post by brianfry713 »

There should be spaces at the end of the last two lines of the sample output.
Check input and AC output for thousands of problems on uDebug!

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

Re: 490 - Rotating Sentences

Post by xtine.m »

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--;
			}
		}
	} 

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentences

Post by brianfry713 »

There should be spaces, not null characters. Post your full code.
Check input and AC output for thousands of problems on uDebug!

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

Re: 490 - Rotating Sentences

Post by xtine.m »

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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentences

Post by brianfry713 »

Line 58 should be %c not %d.
Check input and AC output for thousands of problems on uDebug!

@ce
Learning poster
Posts: 71
Joined: Mon May 28, 2012 8:46 am
Location: Ranchi, India

Re: 490 - Rotating Sentences

Post by @ce »

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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentences

Post by brianfry713 »

You're printing an extra line at the end with two spaces.
Check input and AC output for thousands of problems on uDebug!

@ce
Learning poster
Posts: 71
Joined: Mon May 28, 2012 8:46 am
Location: Ranchi, India

Re: 490 - Rotating Sentences

Post by @ce »

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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentences

Post by brianfry713 »

Don't print an extra blank line at the end. The last line should be quotes, space, newline.
Check input and AC output for thousands of problems on uDebug!

shikhar.atri
New poster
Posts: 1
Joined: Wed Jan 09, 2013 3:25 pm

Re: 490 - Rotating Sentences

Post by shikhar.atri »

GETTING WRONG ANSWER.....SOMEBODY PLZ TELL ME WATS WRNG WID DA CODE

Code: Select all

  #include<iostream>
  #include<cstdio>
  #include<cmath>
  #include<cstdlib>
  #include<cstring>
  #include<algorithm>
  #include<vector>
  #include<stack>
  #include<deque>
  #include<queue>
  #include<utility>
  # define U unsigned long long int
  # define L long long int
  # define INF 2147483648
  using namespace std;
  int main()
  {
      string s[100];
      int size[100];
      //getchar();
      int i=0,k=0;
      while(getline(cin,s[i]))
      {
          size[i]=s[i].size();
          if(k<size[i])k=size[i];
          i++;                
      }
      int n=i;
      /*for(int i=0;i<n;i++)
      {
              cout<<s[i];        
      }*/
      int j=0;
      //cout<<k<<endl;
      while(1)
      {
              for(int i=n;i>=0;i--)
              {
                 if(j<s[i].size())
                 {
                     cout<<s[i].at(j);                               
                 }          
              }
              cout<<endl;
              j++;
              if(j==k)break;
              
      }
      //system("pause");
  }

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentences

Post by brianfry713 »

For the sample input, there should be a space at the end of the last two lines of the output.
Check input and AC output for thousands of problems on uDebug!

mfjuzar
New poster
Posts: 3
Joined: Thu Mar 28, 2013 6:37 am

Re: 490 - Rotating Sentences

Post by mfjuzar »

Im having the same problem, but its in pascal language, the output seems to match exactly as written in the problem, whats wrong?

Code: Select all

var
txt1,txt2: string;
i,l:integer;

begin
readln(txt1);
readln(txt2);

if length(txt1)> length(txt2) then 
	l:=length(txt1)
	else
	l:=length(txt2);

for i:= 1 to l do begin
write(txt2[i]);
write(txt1[i]);
if i=l then else writeln;
end;

end.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentences

Post by brianfry713 »

brianfry713 wrote:For the sample input, there should be a space at the end of the last two lines of the output.
Check input and AC output for thousands of problems on uDebug!

hello
New poster
Posts: 25
Joined: Sun Mar 10, 2013 7:29 pm

Re: 490 - Rotating Sentences

Post by hello »

What is the problem

Code: Select all

  Deleted after got AC
Last edited by hello on Fri Jul 12, 2013 3:37 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentences

Post by brianfry713 »

Next time post your full code.

Try either making arr global or add memset(arr, 0, sizeof(arr))
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 4 (400-499)”