結果

問題 No.784 「,(カンマ)」
ユーザー heyanxxheyanxx
提出日時 2019-07-11 11:01:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 4,241 ms
コンパイル使用メモリ 83,556 KB
実行使用メモリ 42,564 KB
最終ジャッジ日時 2024-04-25 00:15:36
合計ジャッジ時間 6,643 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
42,220 KB
testcase_01 AC 145 ms
42,276 KB
testcase_02 AC 124 ms
41,008 KB
testcase_03 AC 114 ms
40,308 KB
testcase_04 AC 114 ms
39,904 KB
testcase_05 AC 113 ms
40,300 KB
testcase_06 AC 128 ms
41,384 KB
testcase_07 AC 128 ms
41,460 KB
testcase_08 AC 137 ms
41,816 KB
testcase_09 AC 150 ms
42,564 KB
testcase_10 AC 148 ms
42,404 KB
testcase_11 AC 148 ms
42,484 KB
testcase_12 AC 144 ms
42,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package test.demo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Yukicoder784 {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		int N =sc.nextInt();
		if(N>999) {
			String str=String.valueOf(N);
			int a=str.length()%3;
		if(a!=0) {	
			String str2=str.substring(0,a)+",";
			for(int i=a;i<str.length()-a;i=i+3) {
				if(i+3>=str.length()) {
					str2+=str.substring(i,str.length());
				}else {
				str2+=str.substring(i,i+3)+",";
				}
		}
			System.out.println(str2);
		}else {
			String str2="";
			for(int i=0;i<str.length();i=i+3) {
				if(i+3>=str.length()) {
					str2+=str.substring(i,str.length());
				}else {
				str2+=str.substring(i,i+3)+",";
				}
			}
			System.out.println(str2);
		}
			
		}else {
			System.out.println(N);
		}

	}

}
0