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

uvasarker
Learning poster
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh
Contact:

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

Post by uvasarker » Sat Jan 07, 2012 6:17 am

Hi brianfry713,
Thank you very much for kindly help.
Now, it's still WA. Please, tell me where is the problem in my code. Here is my modified code.

Code: Select all

#include<stdio.h>
#include<string.h>
int main()
{

	while(true)
	{
	char s1[101]={'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'};
	char s2[101]={'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'};
		int max,len1,len2;
			gets(s1);
			len1=strlen(s1);
			if(s2[0]=='\0' && s1[0]!='\0')
			{
				gets(s2);
				len2=strlen(s2);
			}
			if(s2[0]=='\0' && s1[0]=='\0') break;
			if(len1>len2)
			{
					max=len1;
			}
			
			else if(len2>len1)
			{
					max=len2;
			}
			else
					max=len1;
					
					
			int fag=0;
			for(int i=0 ; i<max ; i++)
			{
				printf("%c%c\n",s2[i],s1[i]);
				//if(i<max-1) printf("\n");
				fag++;
			}

			if(fag!=0)
			{
					for(int i=0 ; i<max ; i++)
					{
							s2[0]='\0';
					}
			}

	}
	return 0;
}


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 » Thu Jan 19, 2012 1:30 am

You're still assuming there are always two sentences, there could be up to 100, each of length up to 100. You also can't print the null characters at the end of a line, those should be spaces.

Try this input at http://www.uvatoolkit.com/problemssolve.php
Sentence one.
Sentence two is longer.
Shorter.
Check input and AC output for thousands of problems on uDebug!

wz0o0zw
New poster
Posts: 3
Joined: Mon Mar 19, 2012 5:33 pm

Please Help!!!! 490 Runtime Error

Post by wz0o0zw » Mon Mar 19, 2012 5:46 pm

plz help, i don't know why i always get Runtime Error!plz help me,thanks.
and this is my code:

#include <iostream>
#include <stdio.h>
#define R 100
#define L 100
using namespace std;
int main()
{
freopen("490.txt","r",stdin);
char rot[L][R];
int n=0;
for(int i=0;i<100;i++)
for(int j=0;j<100;j++)
rot[j]='\0';
while(gets(rot[n]))
if(n<100)
n++;
for(int i=0;i<100;i++)
{
for(int j=0;j<n;j++)
if(rot[j]!='\0')
{
cout<<rot[j];
if(j==n-1)
cout<<endl;
}
else continue;
}
return 0;
}


and the 490.txt is:

Rene Decartes once said,
"I think, therefore I am."

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

Re: Please Help!!!! 490 Runtime Error

Post by brianfry713 » Mon Mar 19, 2012 8:40 pm

Read the input from stdin, not a file.
Check input and AC output for thousands of problems on uDebug!

wz0o0zw
New poster
Posts: 3
Joined: Mon Mar 19, 2012 5:33 pm

Re: Please Help!!!! 490 Runtime Error

Post by wz0o0zw » Tue Mar 20, 2012 4:44 pm

brianfry713 wrote:Read the input from stdin, not a file.
#include <iostream>
#include <stdio.h>
#define R 100
#define L 100
using namespace std;
int main()
{
char rot[L][R];
int n=0;
for(int i=0;i<100;i++)
for(int j=0;j<100;j++)
rot[j]='\0';
while(gets(rot[n]))
if(n<100)
n++;
for(int i=0;i<100;i++)
{
for(int j=0;j<n;j++)
if(rot[j]!='\0')
{
cout<<rot[j];
if(j==n-1)
cout<<endl;
}
else continue;
}
return 0;
}

When I submit,i don't use "stdin" or "490.txt", i just use the codes above. But always i get Runtime Error,and i really don't understand.

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

Re: Please Help!!!! 490 Runtime Error

Post by brianfry713 » Tue Mar 20, 2012 9:38 pm

This doesn't match the sample I/O.
Check input and AC output for thousands of problems on uDebug!

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

490 - Rotating Sentences

Post by @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

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

Re: 490 - Rotating Sentences

Post by brianfry713 » Fri Jun 01, 2012 12:33 am

Try the sample I/O again.
Check input and AC output for thousands of problems on uDebug!

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

Re: 490 - Rotating Sentences

Post by @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

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

Re: 490 - Rotating Sentences

Post by 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.
Check input and AC output for thousands of problems on uDebug!

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

Re: 490 - Rotating Sentences

Post by @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

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

Re: 490 - Rotating Sentences

Post by 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.
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 » 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;
}


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

Re: 490 - Rotating Sentences

Post by 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.
Check input and AC output for thousands of problems on uDebug!

uvasarker
Learning poster
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh
Contact:

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

Post by uvasarker » Sun Jun 17, 2012 5:44 pm

Guru
Please check.......Why W A?

Code: Select all

#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int main()
{
	char in[101][110], s[101];
	int len[101], ln, l=0, maxx=0;
//	freopen("490.txt","r",stdin);
//	freopen("490_OUT.txt","w",stdout);
		while(gets(s))
		{
			ln=strlen(s);
			len[l]=ln;
			if(ln>maxx) maxx=ln;
			for(int i=0 ; i<ln ; i++)
				in[l][i]=s[i];
			l++;
		}

            for(int j=0 ; j<maxx ; j++)
            {
				for(int i=l-1 ; i>=0 ; i--)
				{
				    if(in[i][j]!='\0')
                        printf("%c",in[i][j]);
				}
				printf("\n");
            }

	return 0;
}


Post Reply

Return to “Volume 4 (400-499)”