Page 7 of 9
Why compilation Error?!!!!
Posted: Thu May 12, 2011 9:20 pm
by tanvirfromhell
Why I got compilation error?!!!
Code: Select all
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char a[1000];
while(scanf("%s",&a)==1)
{
if(a[0]=='\n' || a[1]=='\n')
printf("\n");
else
printf("%s ",strrev(a));
}
return 0;
}
483 TLE
Posted: Sat Dec 10, 2011 7:29 am
by mahfuzsust001
Where is my mistake, I cant find it.. MY code is here......
#include <stdio.h>
#include <string.h>
int main()
{
char str[90000];
int i,j,t,len;
while(gets(str))
{
t=0;
len = strlen(str);
for(i=0;i<=len;i++)
{
if(str==' ' || i==len)
{
for(j=i-1;j>=t;j--) printf("%c",str[j]);
printf("%c",str);
t=i+1;
}
}
printf("\n");
}
return 0;
}
Re: 483 TLE
Posted: Sat Jan 07, 2012 12:03 am
by brianfry713
You're printing a null character at the end of each line. Don't use gets().
Use the existing thread for a problem. Use the code tags.
Re: 483
Posted: Sat Jun 30, 2012 11:47 pm
by PromeNabid
I have a question, what should happen if there is a space right before end of line ?? My code does not get the line feed for this. I did not used "gets".
At first got Wa. I read all the clarifications then Accepted. Some samples by my AC code.
Input:
Code: Select all
I love you.
You love me.
The output will consist
of the same lines and words as the input file.
However, the letters within each word must be reversed.
Output:
Code: Select all
I evol .uoy
uoY evol .em
ehT tuptuo lliw tsisnoc
fo eht emas senil dna sdrow sa eht tupni .elif
,revewoH eht srettel nihtiw hcae drow tsum eb .desrever
483 PE
Posted: Fri Jul 06, 2012 7:34 am
by sonjbond
um getting PE ,,,, I/O is okk ... but PE ... plzzz help me.. m
Re: 483 TLE
Posted: Fri Jul 06, 2012 1:14 pm
by sonjbond
yaaa,, get AC now ...

Re: 483
Posted: Tue Aug 21, 2012 7:57 pm
by stride
i presume all my outputs are right, am i printing something invisible to the naked eye here? coz i got WA with this code..
Code: Select all
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main()
{
char string[9999];
char out[9999];
int j=0,k=0;
int length;
while(scanf("\n%[^\n]",&string)!=EOF)
{
length = strlen(string);
for(int i=0;i<length;i++)
{
if(string[i]==' ')
{
j=i-1;
while(string[j]!=' ' && j>=0)
{
out[k] = string[j];
j--;k++;
}
out[k] = ' ';
k++;
}
else if(i == length-1)
{
j = length - 1;
while(string[j]!=' ')
{
out[k] = string[j];
j--;k++;
}
}
}
cout<<out<<endl;
k=0;
}
return 0;
}
Re: 483
Posted: Tue Aug 21, 2012 10:19 pm
by brianfry713
Try the I/O gba356 posted in this thread. Your code ignores spaces at the beginning of a line.
Re: 483
Posted: Mon Oct 08, 2012 7:55 pm
by gr81
getting WA...please have a look...
#include <iostream>
#include <vector>
#include <string>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
using namespace std;
void reverse(char *str, int start, int end)
{
if( start < end )
{
char tmp = str[start];
str[start] = str[end];
str[end] = tmp;
reverse(str, ++start, --end);
}
}
void process(char *str)
{
int len = strlen(str);
int start, end;
start = end = 0;
bool in_word = false;
int wc = 0;
for(int i=0; i <= len; ++i)
{
if( isalpha(str))
{
if(!in_word)
{
in_word = true;
start = i;
}
}
else if( (str == ' ') || (str == '\n') || (str == '\0'))
{
if(in_word)
{
in_word = false;
end = i-1;
reverse(str, start, end);
wc++;
}
}
}
}
int main()
{
vector<string> vs;
char str[90000] = {0};
while( scanf("%[^\n]", &str) != EOF)
{
getchar();
string lstr(str);
vs.push_back(lstr);
process((char*)lstr.c_str());
lstr.clear();
memset(&str, 0, sizeof(str));
}
vector<string>::iterator it;
for(it=vs.begin(); it != vs.end(); ++it)
{
cout << *it << endl;
}
return 0;
}
Thanks in Advance.
Re: 483
Posted: Mon Oct 08, 2012 9:00 pm
by brianfry713
Try updating your code to not print a newline at the end of a line if EOF is reached.
Re: 483
Posted: Tue Oct 09, 2012 7:55 pm
by gr81
sorry I didn't get your doubt....
Re: 483
Posted: Tue Oct 09, 2012 8:43 pm
by brianfry713
For input "asdf\n" the output should be "fsda\n".
For input "asdf", the output should be "fdsa", your code prints "fdsa\n".
Re: 483 Word Scramble PE!!!!!!!!!!!!!
Posted: Mon Jul 15, 2013 6:45 pm
by varrlo
Well I got WA and I have no idea what is the problem. Is it because of new line in the end of output?
Re: 483 Word Scramble PE!!!!!!!!!!!!!
Posted: Mon Jul 15, 2013 11:28 pm
by brianfry713
For input a.b output should be b.a
Re: 483 Word Scramble PE!!!!!!!!!!!!!
Posted: Tue Jul 16, 2013 12:14 am
by varrlo
So shall i just delete
? will it work?
nvm worked got AC