-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2022-04-19.cpp
More file actions
80 lines (65 loc) · 1.01 KB
/
2022-04-19.cpp
File metadata and controls
80 lines (65 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <stack>
using namespace std;
void P1();
void P2();
void P3();
int main() {
P3();
return 0;
}
void P1() {
string str;
stack<char> st;
cin >> str;
for (int i = 0; i < str.length(); i++) {
st.push(str[i]);
}
for (int i = 0; i < str.length(); i++) {
cout << st.top();
st.pop();
}
cout << endl;
}
void P2() {
stack<stack<char>> st;
string str[3];
cin >> str[0] >> str[1] >> str[2];
stack<char> temp;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < str[i].size(); j++) {
temp.push(str[i][j]);
}
st.push(temp);
while (!temp.empty())
{
temp.pop();
}
}
while (!st.empty()) {
while (!st.top().empty()) {
cout << st.top().top();
st.top().pop();
}
cout << endl;
st.pop();
}
}
void P3() {
stack<char> s;
string num;
cin >> num;
for (int i = num.length() - 1, cnt = 1; i >= 0; i--, cnt++) {
s.push(num[i]);
if (cnt % 3 == 0) {
if (i == 0) {
break;
}
s.push(',');
}
}
while (!s.empty()) {
cout << s.top();
s.pop();
}
}