結果

問題 No.784 「,(カンマ)」
ユーザー Eclair1015Eclair1015
提出日時 2019-02-28 23:44:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,809 bytes
コンパイル時間 1,103 ms
コンパイル使用メモリ 119,088 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 16:23:40
合計ジャッジ時間 1,959 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<deque>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<tuple>
#include<map>
#include<memory>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<double> VD;
typedef pair<int, int> P1;
typedef long long int ll;

//number
#define INF 1e9
#define NUM 1000000007

//itr
#define all(x) begin(x),end(x)

//repeat
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define RREPS(i,x) for(int i=((int)(x));i>=0;i--)

//max,min
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

/*ll gcd(ll a, ll b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}*/

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a * (b / g);
}*/

/*int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}*/

//grid template
int x[] = { -1, 0, 1, 0 };
int y[] = { 0,-1,0,1 };
int xx[] = { -1,-1,1,1 };
int yy[] = { 1,-1,1,-1 };

int main() {
	string s;
	cin >> s;
	if (s.size() <= 3) {
		cout << s << endl;
		return 0;
	}

	if (s.size() % 3 == 0) {
		rep(i, s.size()) {
			if (i % 3 == 0 && i != 0) {
				cout << ',';
			}
			cout << s[i];
		}
	} else if (s.size() % 3 == 1) {
		cout << s[0]<<',';
		int cnt = 0;
		REP(i, 1, s.size()) {
			if (cnt % 3 == 0 && cnt != 0) {
				cout << ',';
			}
			cout << s[i];
			cnt++;
		}
	} else if (s.size() % 3 == 2) {
		cout << s[0] <<s[1]<< ',';

		int cnt = 0;
		REP(i, 2, s.size()) {
			if (cnt % 3 == 0 && cnt != 0) {
				cout << ',';
			}
			cout << s[i];
			cnt++;
		}
	}

	cout << "\n";




}




 
0