OSgood의 개발일기

[CodeUp]2016 천단위 구분기호 본문

Algorithm/Algorithm 문제 연습

[CodeUp]2016 천단위 구분기호

OSgood 2019. 9. 10. 15:31

2016 천단위 구분기호

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
#include <iostream>
#include <stack>
#include <vector>
 
using namespace std;
int main() {
   int a;
   char cs[1000];
   stack<char> st;
   vector<char> result;
 
   cin >> a;
   cin >> cs;
   int i = 0;
   while (cs[i] != '\0')
   {
      st.push(cs[i]);
      i++;
   }
 
   char tmp;
   int cnt = 0;
   while (!st.empty())
   {
      cnt++;
      if (cnt % 4 == 0)
      {
         result.push_back(',');
      }
      else
      {
         tmp = st.top();
         result.push_back(tmp);
         st.pop();
      }
      
   }
 
   vector<char>::reverse_iterator itr = result.rbegin();
   for (itr;itr !=result.rend(); itr++)
   {
      cout << *itr;
   }
 
   return 0;
}
cs

 

Comments