20年度FE秋期試験午後問10
20年度秋期試験の問題解いてみたけど、午前が77%で午後が85%位の得点率だった。
7割5分くらい取れれば良いそうなので、結構ギリギリw
全体の60%で大丈夫って書いてあるところもあるし、一問一問の配点が違うから、みんなが解ける問題は絶対に解くようにしよう!とか書いてあるところもあるし、よーわかりませんわ。
要するに取り合えず満点目指してガンバローってことでしょ?
午後問10がなかなか面白かったので、動かせる状態にプログラミング。
文字テーブルの初期化のときにrand関数を使っているので、その前にパスワードみたいなの入力&パスワードを数値化して、srandのseedに使えば、もっとそれっぽくなるかもしれないw
/////////////////////////////////////////////////////////// // 基本情報技術者試験 平成20年度秋期試験 // // 午後試験問10をちょっと改変 /////////////////////////////////////////////////////////// #include <stdio.h> #include <string.h> #include <stdlib.h> #define ROWS 4 #define COLS 23 char ctbl[ROWS][COLS]; void init(); void crypt(const char* in_file, const char* out_file, int flag); void encrypt(const char* in_file, const char* out_file); void decrypt(const char* in_file, const char* out_file); /////////////////////////////////////////////////////////// // main /////////////////////////////////////////////////////////// int main(int argc, char *argv[]) { init(); encrypt("input.txt", "output.txt"); return 0; } /////////////////////////////////////////////////////////// // 文字テーブルの初期化 /////////////////////////////////////////////////////////// void init() { char symbol[ROWS*COLS+1]; char ch; int i = 0, j; ch = ' '; while (i < ROWS*COLS) { if (ch == '$' || ch == '@' || ch == '`') { ch++; } else { symbol[i++] = ch; ch++; } } symbol[ROWS*COLS] = '\0'; for (i = 0;i < 1000;i++) { int idx1 = rand()%(ROWS*COLS); int idx2 = rand()%(ROWS*COLS); ch = symbol[idx1]; symbol[idx1] = symbol[idx2]; symbol[idx2] = ch; } for (i = 0;i < ROWS;i++) { for (j = 0;j < COLS;j++) { ctbl[i][j] = symbol[i*COLS+j]; putchar(ctbl[i][j]); } putchar('\n'); } } /////////////////////////////////////////////////////////// // 暗号・復号化 // // flag -- 0 暗号化 // -- 1 復号化 /////////////////////////////////////////////////////////// void crypt(const char* in_file, const char* out_file, int flag) { FILE *ifp, *ofp; char ch[2]; int col[2], row[2], flg, i, sts, cols, rows; if (flag == 0) { cols = 1; rows = 1; } else { cols = COLS-1; rows = ROWS-1; } ifp = fopen(in_file, "r"); ofp = fopen(out_file, "w"); do { sts = fgetc(ifp); if (sts != EOF) { ch[0] = sts; sts = fgetc(ifp); if (sts == EOF) { ch[1] = ' '; } else { ch[1] = sts; } for(i = 0; i < 2; i++){ flg = 0; for (row[i] = 0; row[i] < ROWS; row[i]++) { for (col[i] = 0; col[i] < COLS; col[i]++) { if (ch[i] == ctbl[row[i]][col[i]]) { flg = 1; break; } } if(flg != 0) break; } } if (row[0] == row[1]) { if (col[0] == col[1]) { ch[0] = ch[1] = ctbl[(row[0]+rows) % ROWS][(col[0]+cols) % COLS]; } else { ch[0] = ctbl[row[0]][(col[0]+cols) % COLS]; ch[1] = ctbl[row[1]][(col[1]+cols) % COLS]; } } else if(col[0] == col[1]) { ch[0] = ctbl[(row[0]+rows) % ROWS][col[0]]; ch[1] = ctbl[(row[1]+rows) % ROWS][col[1]]; } else { ch[0] = ctbl[row[0]][col[1]]; ch[1] = ctbl[row[1]][col[0]]; } fputc(ch[0], ofp); fputc(ch[1], ofp); } } while (sts != EOF); fclose(ifp); fclose(ofp); } /////////////////////////////////////////////////////////// // 暗号化 /////////////////////////////////////////////////////////// void encrypt(const char* in_file, const char* out_file) { crypt(in_file, out_file, 0); } /////////////////////////////////////////////////////////// // 復号化 /////////////////////////////////////////////////////////// void decrypt(const char* in_file, const char* out_file) { crypt(in_file, out_file, 1); } -input.txt- FE2007FALL[EOF] -output.txt- PdkvhWVJDD[EOF]