UVa 483 - Word Scramble

时间:2023-03-09 02:11:18
UVa 483 - Word Scramble

  题目大意:给一个由单词组成的句子,只反转单词内部的次序而不改变单词之间的次序。如“I love you.”转换成“I evol .uoy”。

 #include <cstdio>
#include <cstring> int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int s, e;
char str[];
while (gets(str))
{
bool in_word = false;
int len = strlen(str);
int p = ;
while (p < len)
{
while (p < len && str[p] == ' ')
{
putchar(' ');
p++;
}
s = p;
while (p < len && str[p] != ' ') p++;
e = p - ;
for (int i = e; i >= s; i--)
putchar(str[i]);
}
printf("\n");
}
return ;
}