Skip to content

Commit 25f2a07

Browse files
committed
add new cod
1 parent 434bbce commit 25f2a07

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

a.out

-30.2 KB
Binary file not shown.

reverse-words-in-a-given-string.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// https://practice.geeksforgeeks.org/problems/reverse-words-in-a-given-string/0
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
int main(){
6+
string s;
7+
stack<string> st;
8+
// cin>>s;
9+
char str[1000];
10+
cin.getline(str,sizeof(str));
11+
// const char *str = s.c_str();
12+
char *pch;
13+
pch = strtok(str," ");
14+
// cout << str << endl;
15+
while(pch){
16+
st.push(pch);
17+
cout << pch << " ";
18+
pch = strtok(NULL," ");
19+
}
20+
while(!st.empty()){
21+
cout << st.top() << " ";
22+
cout << endl;
23+
st.pop();
24+
}
25+
return 0;
26+
}

0 commit comments

Comments
 (0)