「コリンク-Keitai Message」の編集履歴(バックアップ)一覧はこちら
「コリンク-Keitai Message」(2010/04/25 (日) 16:37:42) の最新版変更点
追加された行は緑色になります。
削除された行は赤色になります。
/*
Problem A: Keitai Message
制作時間:2010/4/24 17:40~2010/4/24 18:51 (71分)
作者:加賀谷享諒
ID:s7509413
[解き方]
いつものことだが、プログラムを作りながら作り方を決めていった。
そろそろプログラムを作る前に事前にプログラム設計などをした方がいいのだろうか。
[手間取った点]
複数のトラブルが同時に発生し、原因の特定が困難となった。
* VC++ の cl でコンパイルしたときに /EHsc オプションを指定しないと std::vector でエラーが出る。 (vector を include しただけで。)
* fgets と scanf の混在で入力が想定外のものになる。
* setChCode 関数で obj[i].n = i; としていた。
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#define INP_MAX 1024
#define OUT_MAX 128
#define DEBUG 0
struct chcode_t{
std::vector<char> ch;
int n;
};
void inputStr(char *str, int arrLen, FILE *fp)
{ /* str に fp からの文字列を入力する。 arrayLen は配列の長さ。 */
fgets(str, arrLen, fp);
if(str[arrLen = (int)strlen(str) - 1] == '\n'){
str[arrLen] = '\0';
}else{
fflush(stdin);
}
return;
}
void inputInt(int &val){
char s[256];
inputStr(s, sizeof(s)/sizeof(s[0]), stdin);
val = atoi(s);
return;
}
void setChCode(struct chcode_t *obj){
char *b[] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
int i, j;
for(i = 0; i < 9; ++i){
for(j = 0; j < 6 && b[i][j] != '\0'; ++j){
obj[i].ch.push_back(b[i][j]);
}
obj[i].n = j;
}
return;
}
void setC(char *s, char ch, int i){
if(i + 1 < OUT_MAX){
s[i] = ch;
s[i+1] = '\0';
}
return;
}
int main(int argc, char *argv[]){
int n; /* テストケース数 */
char input[INP_MAX], output[OUT_MAX];
struct chcode_t chcode[9]; /* 文字割り当て */
int i, nowBt, beforeBt, nowCh;
char *inpP;
setChCode(chcode); /* ボタンに文字を割り当てる。 */
#if DEBUG
{ /* 文字割り当てを表示 */
int j;
for(i = 0; i < 9; ++i){
for(j = 0; j < chcode[i].n; ++j){
printf(" %c", chcode[i].ch[j]);
}
puts("");
}
}
#endif
inputInt(n); /* テストケース数入力 */
for(; n > 0; --n){
inputStr(input, sizeof(input)/sizeof(input[0]), stdin); /* テストケース入力 */
i = 0;
nowBt = 0;
nowCh = -1;
for(inpP = input; *inpP != '\0'; ++inpP){
beforeBt = nowBt;
nowBt = *inpP - '0';
if(nowBt > 0){
nowCh = (nowCh + 1) % chcode[nowBt-1].n;
}else{
if(beforeBt){
output[i] = chcode[beforeBt-1].ch[nowCh];
++i;
output[i] = '\0';
nowCh = -1;
}
}
}
puts(output);
}
return 0;
}
/*
Problem A: Keitai Message
制作時間:2010/4/24 17:40~2010/4/24 18:51 (71分)
作者:コリンク
ID:s7509413
[解き方]
いつものことだが、プログラムを作りながら作り方を決めていった。
そろそろプログラムを作る前に事前にプログラム設計などをした方がいいのだろうか。
[手間取った点]
複数のトラブルが同時に発生し、原因の特定が困難となった。
* VC++ の cl でコンパイルしたときに /EHsc オプションを指定しないと std::vector でエラーが出る。 (vector を include しただけで。)
* fgets と scanf の混在で入力が想定外のものになる。
* setChCode 関数で obj[i].n = i; としていた。
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#define INP_MAX 1024
#define OUT_MAX 128
#define DEBUG 0
struct chcode_t{
std::vector<char> ch;
int n;
};
void inputStr(char *str, int arrLen, FILE *fp)
{ /* str に fp からの文字列を入力する。 arrayLen は配列の長さ。 */
fgets(str, arrLen, fp);
if(str[arrLen = (int)strlen(str) - 1] == '\n'){
str[arrLen] = '\0';
}else{
fflush(stdin);
}
return;
}
void inputInt(int &val){
char s[256];
inputStr(s, sizeof(s)/sizeof(s[0]), stdin);
val = atoi(s);
return;
}
void setChCode(struct chcode_t *obj){
char *b[] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
int i, j;
for(i = 0; i < 9; ++i){
for(j = 0; j < 6 && b[i][j] != '\0'; ++j){
obj[i].ch.push_back(b[i][j]);
}
obj[i].n = j;
}
return;
}
void setC(char *s, char ch, int i){
if(i + 1 < OUT_MAX){
s[i] = ch;
s[i+1] = '\0';
}
return;
}
int main(int argc, char *argv[]){
int n; /* テストケース数 */
char input[INP_MAX], output[OUT_MAX];
struct chcode_t chcode[9]; /* 文字割り当て */
int i, nowBt, beforeBt, nowCh;
char *inpP;
setChCode(chcode); /* ボタンに文字を割り当てる。 */
#if DEBUG
{ /* 文字割り当てを表示 */
int j;
for(i = 0; i < 9; ++i){
for(j = 0; j < chcode[i].n; ++j){
printf(" %c", chcode[i].ch[j]);
}
puts("");
}
}
#endif
inputInt(n); /* テストケース数入力 */
for(; n > 0; --n){
inputStr(input, sizeof(input)/sizeof(input[0]), stdin); /* テストケース入力 */
i = 0;
nowBt = 0;
nowCh = -1;
for(inpP = input; *inpP != '\0'; ++inpP){
beforeBt = nowBt;
nowBt = *inpP - '0';
if(nowBt > 0){
nowCh = (nowCh + 1) % chcode[nowBt-1].n;
}else{
if(beforeBt){
output[i] = chcode[beforeBt-1].ch[nowCh];
++i;
output[i] = '\0';
nowCh = -1;
}
}
}
puts(output);
}
return 0;
}
表示オプション
横に並べて表示:
変化行の前後のみ表示: