結果

問題 No.784 「,(カンマ)」
ユーザー outline
提出日時 2020-03-19 02:19:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 469 bytes
コンパイル時間 1,982 ms
コンパイル使用メモリ 171,348 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-14 02:55:25
合計ジャッジ時間 2,990 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int n = s.length();
    if(n <= 3){
        cout << s << endl;
        return 0;
    }
    stack<char> st;
    int cnt = 0;
    int pos = n - 1;
    while(pos >= 0){
        st.push(s[pos--]);
        ++cnt;
        if(cnt % 3 == 0)    st.push(',');
    }
    if(n % 3 == 0)  st.pop();
    while(!st.empty()){
        cout << st.top();
        st.pop();
    }
    cout << endl;
}
0