[CodeUp] #2016-천단위 구분기호(스택)

chrmqgozj·2022년 1월 21일
0

CodeUp

목록 보기
15/48
#include <iostream>
#include <stack>
using namespace std;

int main(){
	int n,cnt=0;
	string num;
	stack<char> s;
	
	cin >> n;
	cin >> num;
	
	while(cnt<n){
		if(cnt%3==0 && cnt>0 && cnt<n){
			s.push(',');
			//cout << s.top() << "\n";
		}
		s.push(num[num.size()-cnt-1]);
		// cout << s.top() << "\n";
		cnt++;
	}
	
	// cout << s.size() << "\n";

	while(!s.empty()){
		cout << s.top();
		s.pop();
	}
	
}

0개의 댓글

관련 채용 정보