可利用sscanf或是stringstream會用空白來隔開輸入的特性來做。
C++(0.008)
/*******************************************************/
/* UVa 483 Word Scramble */
/* Author: Maplewing [at] knightzone.studio */
/* Version: 2012/03/18 */
/*******************************************************/
#include<iostream>
#include<sstream>
#include<cstdio>
using namespace std;
int main(){
string s, word;
stringstream ss;
bool space;
while( getline( cin, s ) ){
ss.clear();
ss.str(s);
space = false;
while( ss >> word ){
if( space ) printf( " " );
space = true;
for( int i = word.length()-1 ; i >= 0 ; i-- )
printf( "%c", word[i] );
}
printf( "\n" );
}
return 0;
}