I submitted the below code and received a 'Wrong Answer'. But, it worked for the test cases I tried out. Can anyone help me??
[cpp]
/*"@BEGIN_OF_SOURCE_CODE"*/
#include <stdio.h>
#include <iostream.h>
#include <string.h>
#include <ctype.h>
char* reverseToken (char* inputToken)
{
int strlength = strlen(inputToken);
char* reverse = new char[strlength];
int i = 0;
for (i = 0; i < strlength; i++)
{
reverse = inputToken[strlength - i - 1];
}
reverse = '\0';
return (reverse);
}
char* insertToken(char* dest, int atPos, char* source, int numChars)
{
int i = 0;
for (i = atPos; i < (atPos+numChars); i++ )
{
dest = source[i-atPos];
}
return (dest);
}
int skipSpaces(char* input, int fromPos)
{
char ch = input[fromPos];
int len = strlen(input);
int endPos = fromPos;
while (isspace(ch))
{
endPos++;
if (endPos >= len) break;
ch = input[endPos];
}
return (endPos);
}
char* findToken(char* input, int fromPos)
{
char ch = input[fromPos];
int endPos = fromPos;
int len = strlen(input);
while ( !(isspace(ch)) )
{
endPos++;
if (endPos >= len) break;
ch = input[endPos];
}
int tokenLen = endPos - fromPos;
char* token = new char[tokenLen];
int i =0;
for (i = 0; i < tokenLen; i++)
{
token = input[fromPos+i];
}
token = '\0';
The output will consist of the same lines and words as the input file. However, the letters within each word must be reversed.
2. Enlarge your array size (i don't know the optimal size, but mine is 50000). Also, you only need 1 array to store the char. That way, you just have to process the output everytime you encounter a blank space or end of line.
hi, now iget alltime P.E. - whas the problem may be in my code? is it the problem occuring for putting a newline after the last case? if os then how can i fix that? here is my code:
[cpp]
/*@BEGIN_OF_SOURCE_CODE*/
#include<stdio.h>
#include<ctype.h>
void main()
{
char in[50000];
int i = 0, j = 0, k = 0, l = 0, tab = 0;
while(gets(in) != NULL)
{
i = j = k = l = tab = 0;
Do this trick: read the input with %s first and then do a %c. So you will only read the words and then in the second scanf u will read the white space or newline with the %c. This will reduce a lot of code as well.
int main()
{
char letra[1000],letrar[1000];
int i=0,j,k,p=0,x;
while(letra!='\n')
{
i++;
scanf("%c", &letra);
if (letra==' ')
{
for (j=p,k=i-1;k>=p;j++,k--)
letrar[j]=letra[k];
p=i-1;
letrar[j+1]=' ';
p++;
}
}
if (letra=='\n')
{
for (j=p,k=i-1;k>=p;j++,k--)
letrar[j]=letra[k];
p=i-1;
for (j=0;j<=i-1;j++)
printf("%c",letrar[j]);
}
printf("\n");
i=p=0;
return 0;
}[/c]
It is a simple problem but I can't figure out why I always get WA... if someone know about some special input or what is wrong with my code please let me know...
bye!