トップ 一覧 Farm 検索 ヘルプ RSS ログイン

2005ra3.cの変更点

  • 追加された行はこのように表示されます。
  • 削除された行はこのように表示されます。
 #include <stdio.h>
 #include <string.h>		// 文字列処理のヘッダファイル
 
 #define M 1024	// テストケースの最大の長さ
 #define N 10	// 携帯のボタンの数
 
 int main(void)
 {
 	
 	char str[M + 1] = "";	// テストケースを読み込む文字列
 	
 	// 携帯のボタンの割り当て
 	char button[][6] = {"",			// 0(空文字列、使用しない)
 						".,!? ",	// 1
 						"abc",		// 2
 						"def",		// 3
 						"ghi",		// 4
 						"jkl",		// 5
 						"mno",		// 6
 						"pqrs",		// 7
 						"tuv",		// 8
 						"wxyz",		// 9
 	};
 	
 	int button_len[N] = {0};	// 各ボタンの文字列の長さ
 	
 	int num;		// テストケースの数
 	int str_len;	// テストケースの文字列の長さ
 	char temp;		// 連続する数字
 	int cnt;		// 数字が連続した回数
 	int i, j;		// ループ変数
 	
 	// 各ボタンの文字列の長さを計算
 	for(i = 0; i < N; i++)
 		button_len[i] = strlen(button[i]);
 	
 	// テストケースの数の読み込み
 	scanf("%d", &num);
 	
 	// 各テストケースに対する処理
 	for(i = 0; i < num; i++){
 		
 		
 		scanf("%s", str);		// テストケースの数字列の読み込み
 		
 		str_len = strlen(str);	// テストケースの数字列の長さを計算
 		
 		for(j = 0, temp = str[0]; j < str_len; temp = str[j]){
 			
 			cnt = 0;	// カウントを0に更新
 			
 			// 同じ数字がいくつ連続しているかを調べる
 			while(temp == str[++j])
 				cnt++;
 			
 			// 連続していた数字が0でなければ対応する文字を表示
 			if(temp != '0')
 				printf("%c", button[temp - '0'][cnt % button_len[temp - '0']]);
 		}
 		
 		// 改行
 		putchar('\n');
 	}
 	
 	return (0);
 }