#include<stdio.h>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
using namespace std;
int main(){
stack<string> stack_str;
string str;
string temp;
char temp_ch[100];
while(1){
str="";
cout<<"input string"<<endl;
getline(cin,str);
if(str.size()==0||str.size()<0){
cout<<"input invalide\n";
cout<<"once again"<<endl;
continue;
}
int temp_locate=0;
for(int i=0;;i++){
if(str[i]==' '||i==str.size()){
temp_ch[temp_locate]='\0';
temp=temp_ch;
stack_str.push(temp);
cout<<"temp="<<temp<<endl;
temp="";
temp_locate=0;
if(i==str.size()) break;
while(temp_ch[i+1]==' ') i++;
}
else{
temp_ch[temp_locate++]=str[i];
}
}
str="";
while(!stack_str.empty()){
cout<<"stack_str.top()="<<stack_str.top()<<endl;
temp=stack_str.top();
stack_str.pop();
str+=temp;
if(stack_str.size()==0){
str+=" ";
}
}
cout<<"str="<<str<<endl;
}
return 0;
}
#include<iostream>
#include<string>
#include<queue>
#include<stack>
using namespace std;
int main(){
stack<string> stack_str;
string str;
string temp;
char temp_ch[100];
while(1){
str="";
cout<<"input string"<<endl;
getline(cin,str);
if(str.size()==0||str.size()<0){
cout<<"input invalide\n";
cout<<"once again"<<endl;
continue;
}
int temp_locate=0;
for(int i=0;;i++){
if(str[i]==' '||i==str.size()){
temp_ch[temp_locate]='\0';
temp=temp_ch;
stack_str.push(temp);
cout<<"temp="<<temp<<endl;
temp="";
temp_locate=0;
if(i==str.size()) break;
while(temp_ch[i+1]==' ') i++;
}
else{
temp_ch[temp_locate++]=str[i];
}
}
str="";
while(!stack_str.empty()){
cout<<"stack_str.top()="<<stack_str.top()<<endl;
temp=stack_str.top();
stack_str.pop();
str+=temp;
if(stack_str.size()==0){
str+=" ";
}
}
cout<<"str="<<str<<endl;
}
return 0;
}