Download presentation
Presentation is loading. Please wait.
1
2次元データ処理
2
九九 以下の様な九九の表を作成
3
void main(){ int x, y; for(y=1; y<=9; y++){ for(x=1; x<=9; x++){ printf("%2d ", x*y); } printf("\n");
4
2次元配列を2次元平面に表示 int a[3][3]; a[0][0] = 0; a[0][1] = 1; a[0][2] = 2; a[1][0] =10; a[1][1] =11; a[1][2] =12; a[2][0] =50; a[2][1] =51; a[2][2] =52; a[0][2]を表示 a[1][0]を表示 a[2][1]を表示
5
void main(){ int a[3][3], x, y; a[0][0] = 0; a[0][1] = 1; a[0][2] = 2; a[1][0] =10; a[1][1] =11; a[1][2] =12; a[2][0] =50; a[2][1] =51; a[2][2] =52; for(y=0; y<3; y++){ for(x=0; x<3; x++){ printf("%2d ", a[y][x]); } printf("\n");
6
○× (2次元平面に表示) int a[3][3]; a[0][0] = 2; a[0][1] = 0; a[0][2] = 2; a[1][0] = 0; a[1][1] = 1; a[1][2] = 0; a[2][0] = 1; a[2][1] = 0; a[2][2] = 0; × ・ × 0なら・を表示 ・ ○ ・ 1なら○を表示 ○ ・ ・ 2なら×を表示 a[0][2]を表示 a[1][0]を表示 a[2][1]を表示
7
void main(){ int a[3][3], x, y; a[0][0] = 2; a[0][1] = 0; a[0][2] = 2; a[1][0] = 0; a[1][1] = 1; a[1][2] = 0; a[2][0] = 1; a[2][1] = 0; a[2][2] = 0; for(y=0; y<3; y++){ for(x=0; x<3; x++){ if( a[y][x] == 0 ){ printf("・"); } else if( a[y][x] == 1 ){ printf("○"); } else if( a[y][x] == 2 ){ printf("×"); } printf("\n");
8
○× (そろっているか調査) int a[3][3]; a[0][0] = 1; a[0][1] = 2; a[0][2] = 1; a[1][0] = 2; a[1][1] = 1; a[1][2] = 0; a[2][0] = 1; a[2][1] = 2; a[2][2] = 0; ○ × ○ × ○ ・ ○ × ・
9
void main(){ int a[3][3], x, y, cnt; a[0][0] = 1; a[0][1] = 1; a[0][2] = 1; a[1][0] = 2; a[1][1] = 2; a[1][2] = 0; a[2][0] = 1; a[2][1] = 2; a[2][2] = 0; for(y=0; y<3; y++){ // 横を確認 cnt = 0; for(x=0; x<3; x++){ if( a[y][x] == 1 ){ cnt ++; } if( cnt == 3 ){ printf("縦座標%dにて,○が横にそろっている.\n", y);
10
void main(){ int a[3][3], x, y, cnt; a[0][0] = 1; a[0][1] = 2; a[0][2] = 1; a[1][0] = 2; a[1][1] = 1; a[1][2] = 0; a[2][0] = 1; a[2][1] = 2; a[2][2] = 0; cnt = 0; for(x=0; x<3; x++){ // 斜めを確認 y = 2-x; if( a[y][x] == 1 ){ cnt ++; } if( cnt == 3 ){ printf("右上がり斜めにて,○がそろっている\n");
11
数独 (表示) static int a[9][9] = { 5,3,0,0,7,0,0,0,0, 6,0,0,1,9,5,0,0,0, 0,9,8,0,0,0,0,6,0, 8,0,0,0,6,0,0,0,3, 4,0,0,8,0,3,0,0,1, 7,0,0,0,2,0,0,0,6, 0,6,0,0,0,0,2,8,0, 0,0,0,4,1,9,0,0,5, 0,0,0,0,8,0,0,7,9 }; 問題は, より引用
12
void main(){ int x, y; static int a[9][9] = { 5,3,0,0,7,0,0,0,0, (略) 0,0,0,0,8,0,0,7,9 }; for(y=0; y<9; y++){ for(x=0; x<9; x++){ if( 0 == a[y][x] ){ printf(" ."); } else { printf("%2d", a[y][x]); } printf("\n");
13
数独 (表示) static int a[9][9] = { 5,3,0,0,7,0,0,0,0, 6,0,0,1,9,5,0,0,0, 0,9,8,0,0,0,0,6,0, 8,0,0,0,6,0,0,0,3, 4,0,0,8,0,3,0,0,1, 7,0,0,0,2,0,0,0,6, 0,6,0,0,0,0,2,8,0, 0,0,0,4,1,9,0,0,5, 0,0,0,0,8,0,0,7,9 };
14
int x, y; static int a[9][9] = { 5,3,0,0,7,0,0,0,0, (略) 0,0,0,0,8,0,0,7,9 }; for(y=0; y<9; y++){ if( y % 3 == 0 ){ printf("\n"); } for(x=0; x<9; x++){ if( x % 3 == 0 ){ printf(" "); } if( 0 == a[y][x] ){ printf(" ."); } else { printf("%2d", a[y][x]); } printf("\n");
15
数独 (データの誤りを調査) static int a[9][9] = { 5,3,0,0,7,0,0,0,0, 6,0,0,1,9,5,0,0,0, 0,9,8,0,0,0,0,6,0, 8,0,0,0,6,0,0,0,3, 4,0,0,8,0,3,0,0,1, 7,0,0,0,2,0,0,0,6, 0,6,0,8,0,0,2,8,0, 0,0,0,4,1,9,0,0,5, 0,0,0,0,8,0,0,7,9 };
16
int x, y, n, cnt; static int a[9][9] = { 5,3,0,0,7,0,0,0,0, (略) 0,0,0,0,8,0,0,7,9 }; for(x=0; x<9; x++){ for(n=1; n<=9; n++){ cnt = 0; for(y=0; y<9; y++){ if( a[y][x] == n ){ cnt ++; } } if( 1 < cnt ){ printf("%d %ds at x==%d.\n", cnt, n, x);
17
数独 (データの誤りを調査) static int a[9][9] = { 5,3,0,0,7,0,0,0,0, 6,0,0,1,9,5,0,0,0, 0,9,8,0,0,0,0,6,0, 8,0,0,0,6,0,0,0,3, 4,0,0,8,0,3,0,0,1, 7,0,0,0,2,0,0,0,6, 0,6,0,8,0,0,2,8,0, 0,0,0,4,1,9,0,0,5, 0,0,0,0,8,0,0,7,9 };
18
int x, y, xx, yy, n, cnt; static int a[9][9] = { (略) }; for(xx=0; xx<3; xx++){ for(yy=0; yy<3; yy++){ for(n=1; n<=9; n++){ cnt = 0; for(x=xx*3; x<(xx+1)*3; x++){ for(y=yy*3; y<(yy+1)*3; y++){ if( a[y][x] == n ){ cnt ++; } if( 1 < cnt ){ printf("%d %ds in block (%d,%d).\n", cnt, n, xx, yy);
Similar presentations
© 2024 slidesplayer.net Inc.
All rights reserved.