标签:
HDOJ题目地址:传送门
3 olleh !dlrow m‘I morf .udh I ekil .mca
hello world! I‘m from hdu. I like acm.HintRemember to use getchar() to read ‘\n‘ after the interger T, then you may use gets() to read a line and process it.
题意:输入一个字符串,将字符串中的 单词反转后输出,一次反转一个
#include<stdio.h> #include<iostream> #include<memory.h> #include<string.h> #include<stack> using namespace std; int main(){ int n; char ch; cin>>n; getchar(); while(n--){ string s; stack<char> stack_s; int index=0; while(true){ ch=getchar(); if(ch==' '||ch=='\n'||ch==EOF){ while(!stack_s.empty()){ printf("%c",stack_s.top()); stack_s.pop(); } if(ch=='\n'||ch==EOF) break; /*绝对不能少,控制输出结束*/ printf(" "); }else{ stack_s.push(ch);//入栈 } } printf("\n"); } }
ACM--字母反转--HDOJ 1062--Text Reverse--字符串
标签:
原文地址:http://blog.csdn.net/qq_26891045/article/details/51934894