Page 11 of 15

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

Posted: Sat Jan 07, 2012 6:17 am
by uvasarker
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;
}


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

Posted: Thu Jan 19, 2012 1:30 am
by brianfry713
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.

Please Help!!!! 490 Runtime Error

Posted: Mon Mar 19, 2012 5:46 pm
by wz0o0zw
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."

Re: Please Help!!!! 490 Runtime Error

Posted: Mon Mar 19, 2012 8:40 pm
by brianfry713
Read the input from stdin, not a file.

Re: Please Help!!!! 490 Runtime Error

Posted: Tue Mar 20, 2012 4:44 pm
by wz0o0zw
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.

Re: Please Help!!!! 490 Runtime Error

Posted: Tue Mar 20, 2012 9:38 pm
by brianfry713
This doesn't match the sample I/O.

490 - Rotating Sentences

Posted: Tue May 29, 2012 5:02 pm
by @ce
Getting correct for sample input but getting WA...plzz help me find the error in my code.

Code: Select all

AC

Re: 490 - Rotating Sentences

Posted: Fri Jun 01, 2012 12:33 am
by brianfry713
Try the sample I/O again.

Re: 490 - Rotating Sentences

Posted: Fri Jun 01, 2012 10:21 am
by @ce
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,
.
"

Re: 490 - Rotating Sentences

Posted: Fri Jun 01, 2012 11:42 pm
by brianfry713
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.

Re: 490 - Rotating Sentences

Posted: Sun Jun 03, 2012 3:11 pm
by @ce
@brianfry....java version of the same code is also giving WA...neither i could correct the above C++ code

Code: Select all

AC

Re: 490 - Rotating Sentences

Posted: Mon Jun 04, 2012 10:49 pm
by brianfry713
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.

Re: 490 - Rotating Sentences

Posted: Thu Jun 14, 2012 4:38 am
by xtine.m
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;
}


Re: 490 - Rotating Sentences

Posted: Thu Jun 14, 2012 10:17 pm
by brianfry713
For the sample input, you're printing null characters at the end of the last two lines.

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

Posted: Sun Jun 17, 2012 5:44 pm
by uvasarker
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;
}