483 - Word Scramble
#include <stdio.h>
int main()
{
char line[500000],put[500000], character;
long c,k,i,numberofspace;
while(scanf("%c",&character)!= EOF)
{
c=0;
k=1;
i=0;
numberofspace=0;
line[0]=character;
do
{
if(line[c]==' ' && numberofspace==0)
{
for(long p=i-1;p>=0;p--)
printf("%c",put[p]);
i = 0;
printf("%c",32);
numberofspace +=1;;
}
else if(line[c]==' ' && numberofspace > 0)
{
printf("%c",32);
}
else
{
put[i]=line[c];
i += 1;
numberofspace=0;
}
c +=1;
character = getchar();
line[c]=character;
}while(character != '\n'); // End of do-while
//printf("\n");
for(long p=i-1;p>=0;p--)
printf("%c",put[p]);
printf("\n");
} // End of while
} // End of main
int main()
{
char line[500000],put[500000],
long c,k,i,numberofspace;
while(scanf("%c",&character)!=
{
c=0;
k=1;
i=0;
numberofspace=0;
line[0]=character;
do
{
if(line[c]==' ' && numberofspace==0)
{
for(long p=i-1;p>=0;p--)
printf("%c",put[p]);
i = 0;
printf("%c",32);
numberofspace +=1;;
}
else if(line[c]==' ' && numberofspace > 0)
{
printf("%c",32);
}
else
{
put[i]=line[c];
i += 1;
numberofspace=0;
}
c +=1;
character = getchar();
line[c]=character;
}while(character != '\n'); // End of do-while
//printf("\n");
for(long p=i-1;p>=0;p--)
printf("%c",put[p]);
printf("\n");
} // End of while
} // End of main
Comments
Post a Comment