View Code of Problem 114

 #include<iostream>
 #include <stdio.h>
 #include<string.h>
 #include<algorithm>
 #include<stack>
 using namespace std;
     
  int main(){ 
       string str;
       
	   while(getline(cin,str)){
	   	stack<char> stl;
	   	str.append(" ");
	   	for(int i=0;i<str.length();i++){
	   		if((str[i]>='A'&&str[i]<='Z')||(str[i]>='a'&&str[i]<='z')){
	   			//如果是字符的话入栈
				   stl.push(str[i]);
				    
			   }else{
			   		while(!stl.empty()){
			   			//如果不为空的话,就弹出元素
						   cout<<stl.top();
						   stl.pop(); 
					   }
					   //如果出现其他的非字符元素直接输出
					   if(i!=str.length()-1){
					   	cout<<str[i];
					   } 
			   }
		   }
		   cout<<endl;
	   }  
       	
        	return 0;
        }

Double click to view unformatted code.


Back to problem 114