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
gates1
New poster
Posts: 7 Joined: Tue May 01, 2007 2:11 pm
Post
by gates1 » Tue May 01, 2007 8:44 pm
please help me, this is WA
Code: Select all
var n,i,max:integer;
s:string;
a:array[1..100]of string;
begin
repeat
readln(s);
if length(s)>max then max:=length(s);
for i:=1 to length(s) do
a[i]:=a[i]+s[i];
until eof;
for i:=1 to max do
writeln(a[i]);
readln;
end.
rhsumon
New poster
Posts: 48 Joined: Wed Aug 23, 2006 12:29 pm
Location: Dhaka
Post
by rhsumon » Sun Jun 03, 2007 6:11 pm
Here is my code:
#include<stdio.h>
#include<string.h>
int main()
{
//freopen("490.in", "r", stdin);
//freopen("490.out", "w", stdout);
char str[101], line[101][101];
int len,i,j,k,m_len;
k = 0;
m_len = 0;
for(i=0; i<101; i++)
for(j=0; j<101; j++)
line
[j] = NULL;
while(gets(str) != NULL){
strcpy(line[k], str);
len = strlen(line[k]);
if(m_len < len)
m_len = len;
k++;
}
for(i=0; i<m_len; i++){
for(j=k-1; j>=0; j--){
if(line[j] != 0)
printf("%c",line[j]);
}
printf("\n");
}
//printf("\n");
return 0;
}
Where is the problem??? I can't fix it.....Please anyone help.
Jan
Guru
Posts: 1334 Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:
Post
by Jan » Mon Jun 04, 2007 11:18 pm
Search the board first. Don't open a new thread if there is one already.
Bad Boy
New poster
Posts: 4 Joined: Fri Jul 13, 2007 5:17 am
Location: CSE, DU(13th)
Post
by Bad Boy » Sat Jul 14, 2007 4:23 pm
Accepted, but why spaces are required
Last edited by
Bad Boy on Mon Jul 16, 2007 5:22 pm, edited 1 time in total.
Jan
Guru
Posts: 1334 Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:
Post
by Jan » Sat Jul 14, 2007 5:07 pm
You are checking garbage values. Initialize your array ( a[][] ) with spaces. Hope it helps.
handsomepot
New poster
Posts: 5 Joined: Sun Jul 08, 2007 12:15 pm
Post
by handsomepot » Thu Aug 02, 2007 5:01 pm
I'd made all the test data cotrect on the board.
But I got WA all the time.
Here is my code
#include<stdio.h>
char a[101][101];
int max;
int main()
{
int b[101];
char n;
int i=0,j=0;
int k,m,p=0;
while(scanf("%c",&n)==1)
{
if(n!='\n')
{
a[j]=n;
j++;
}
if(n=='\n')
{
b=j;
if(j>max)
max=j;
i++;
j=0;
}
}
for(m=0;m<max;m++)
for(k=i-1;k>=0;k--)
{
printf("%c",a[k][m]);
if(k==0&&m!=max-1)
printf("\n");
}
return 0;
}
Jan
Guru
Posts: 1334 Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:
Post
by Jan » Thu Aug 02, 2007 7:47 pm
Dont open a new thread if there is one already.
handsomepot
New poster
Posts: 5 Joined: Sun Jul 08, 2007 12:15 pm
Post
by handsomepot » Fri Aug 03, 2007 2:32 am
I'd made all the test data on the boardcotrect .
But I got WA all the time.
Here is my code
#include<stdio.h>
char a[101][101];
int max;
int main()
{
int b[101];
char n;
int i=0,j=0;
int k,m,p=0;
while(scanf("%c",&n)==1)
{
if(n!='\n')
{
a[j]=n;
j++;
}
if(n=='\n')
{
b=j;
if(j>max)
max=j;
i++;
j=0;
}
}
for(m=0;m<max;m++)
for(k=i-1;k>=0;k--)
{
printf("%c",a[k][m]);
if(k==0&&m!=max-1)
printf("\n");
}
return 0;
}
jjtse
Learning poster
Posts: 80 Joined: Mon Aug 22, 2005 7:32 pm
Location: Nevada, US
Contact:
Post
by jjtse » Sat Oct 13, 2007 10:56 am
It handles the above input cases exactly and it still gives me presentation error.
My current program outputs a newline at the end of output. Weird thing is, if I remove that last newline at the end of the output, it'll say wrong answer.
Code: Select all
#include <iostream>
using namespace std;
string str [101];
void printSpaces(int n){
int i;
for (i=0; i<n; i++)
cout <<" ";
}
int main(){
int maxRow = 0;
int i=0;
getline(cin, str[i]);
while (!cin.eof()){
if (maxRow < str[i].length())
maxRow = str[i].length();
i++;
getline(cin, str[i]);
}
int cols=0;
int rows = 0;
for (rows = 0; rows < maxRow; rows++){
int spacesSaved = 0;
for (cols=i; cols>=0; cols--){
if (rows < str[cols].length()){
if (spacesSaved > 0){
printSpaces(spacesSaved);
spacesSaved = 0;
}
cout << str[cols][rows];
}
else
spacesSaved ++;
}
cout << endl;
}
return 0;
}
sapnil
Experienced poster
Posts: 106 Joined: Thu Apr 26, 2007 2:40 pm
Location: CSE-SUST
Contact:
Post
by sapnil » Thu Oct 18, 2007 8:12 am
To jjtse
Trying this case:
Input:
Code: Select all
aaa aaa
aaa
aaa
aaa
a
aaaaaaaaaaaaaaaaaaaaaaa
Output:
Code: Select all
aaaaaa
a aaaa
a aaaa
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a a
a a
a a
** Every input line have same length.
Thanks
Keep posting
Sapnil
"Dream Is The Key To Success"
@@@ Jony @@@
jjtse
Learning poster
Posts: 80 Joined: Mon Aug 22, 2005 7:32 pm
Location: Nevada, US
Contact:
Post
by jjtse » Thu Oct 18, 2007 4:58 pm
Thanks! I got ACCEPTED.
mrmbdctg
New poster
Posts: 18 Joined: Sun Mar 04, 2007 7:12 am
Location: Bangladesh
Contact:
Post
by mrmbdctg » Sat Dec 29, 2007 5:22 pm
Here is my code I always get WA with it
#include<stdio.h>
#include<string.h>
int main()
{
char temp [101], result[100][101];
int k=0,len=0,tempo,i,m,j;
/*freopen("a.out","w",stdout); */
while(gets(temp))
{
strcpy(result[k],temp);
k++;
tempo=strlen(temp);
if(tempo>len)
len=tempo;
}
m=0;
for(i=0;i<len;i++)
{
for(j=k-1;j>=0;j--)
{
printf("%c",result[j][m]);
if(j==0)m++;
}
if(i!=(len-1))
printf("\n");
}
return 0;
}
Thanks in advance. By the way , I always code-- to be a WA man
mrmbdctg
New poster
Posts: 18 Joined: Sun Mar 04, 2007 7:12 am
Location: Bangladesh
Contact:
Post
by mrmbdctg » Sat Dec 29, 2007 5:32 pm
I have posted above code is the logic also wrong I am asking because I always getting WA
Samiul
New poster
Posts: 36 Joined: Thu Dec 13, 2007 3:01 pm
Post
by Samiul » Mon Dec 31, 2007 11:54 am
Hi,
You are printing some garbage at the end. After correcting that try this forum,
http://online-judge.uva.es/board/viewtopic.php?t=5864
try sapnil's input, this is the one which gave me "accepted".
I think the new server got some problem with blank lines and spaces, for this it gave me a lot of trouble with this problem, and for this reason some of the input's, output's on the e-board are not correct anymore for this problem in new server.
mirage
New poster
Posts: 11 Joined: Sat Jan 19, 2008 9:37 pm
Post
by mirage » Sat Feb 02, 2008 8:01 am
what should be out put for this input????
nd further more will i get a WA if i put extra spaces in case like
abcd
abcde
output:
aa
bb
cc
dd
e[space]
Code: Select all
"R Jan
Ie
n
te
h
iD
ne
kc
,a
r
tt
he
es
r
eo
fn
oc
re
e
s
Ia
i
ad
m,
.
"