結果

問題 No.254 文字列の構成
ユーザー ぴろず
提出日時 2015-07-24 23:17:48
言語 Java
(openjdk 23)
結果
AC  
実行時間 140 ms / 5,000 ms
コード長 513 bytes
コンパイル時間 2,490 ms
コンパイル使用メモリ 74,688 KB
実行使用メモリ 42,104 KB
最終ジャッジ日時 2024-07-08 13:45:23
合計ジャッジ時間 6,804 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

package no254;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		StringBuilder ans = new StringBuilder();
		char c = 'a';
		while(n > 1) {
			int x = 1;
			while(x * x + x <= n) {
				x++;
			}
			x--;
			for(int i=0;i<x;i++) {
				ans.append(c);
				ans.append((char) (c+1));
			}
			n -= x * x + x;
			c = c == 'a' ? 'c' : 'a';
		}
		if (n == 1) {
			ans.append('z');
		}
		System.out.println(ans);
	}

}
0