#include < iostream >
#include < string >
using namespace std;
int len = 0 , buf_len = 0 ;
char output[ 255 * 1000 + 2000 ] = { ' \0 ' }, buf[ 300 ] = { ' \0 ' };
char c;
int main() {
// FILE *p = fopen("in.txt", "r");
while (scanf( " %c " , & c) != EOF) {
if ( c >= ' A ' && c <= ' Z ' || c >= ' a ' && c <= ' z ' ) { // 是字母
buf[buf_len ++ ] = c;
}
else {
while (buf_len)
output[len ++ ] = buf[ -- buf_len]; // 倒序存放
output[len ++ ] = c; // 设置间隔符
}
}
while (buf_len) // 有可能在遇到任何特殊符号之前就EOF了,因此buf中的数据也就没有转换到输出中
output[len ++ ] = buf[ -- buf_len];
for ( int i = 0 ;i < len;i ++ )
printf( " %c " , output[i]);
return 0 ;
}
这题目WA了一次test 2,去看了一下DISCUSS,说实在没什么心情自己想原因,心太乱了。
WA的数据就是没有其他字符就直接EOF,原来的程序没想到这一点。想了以后直接AC了。