19 for(col = 0;col < COLLEN;col++)
20 {
21 cell[row][col] = DEAD;
22 }
23 }
24 printf("请先输入一组活细胞的坐标位置,输入(-1-1)结束:\n");
25 while(1)
26 {
27 printf("请输入一个活细胞的坐标位置:");
28 scanf("%d%d",&row,&col);
29 if(0 <= row && row < ROWLEN && 0 <= col && col < COLLEN)
30 {
31 cell[row][col] = ALIVE;
32 }
33 else if(row == -1 || col == -1)
34 {
35 break;
36 }
37 else
38 {
39 printf("输入坐标超过范围。\n");
40 }
41 }
44 int LinSum(int row,int col)
46 int count = 0,c,r;
48 for(r = row - 1;r <= row + 1;r++)
49 {
50 for(c = col - 1; c <= col + 1;c++)
51 {
52 if(r < 0 || r >= ROWLEN || c < 0 || c >= COLLEN)
53 {
54 continue;
55 }
56 if(cell[r][c] == ALIVE)
57 {
58 count++;
59 }
60 }
62 }
63 if(cell[row][col] == ALIVE)
64 {
65 count--;
66 }
67 return count;
70 void OutCell()
72 int row,col;
74 printf("\n细胞状态\n");
75 printf("┌");
76 for(col = 0;col < COLLEN - 1;col++)
77 {
78 printf("──┬");
79 }
80 printf("──┐\n");
81 for(row = 0;row < ROWLEN;row++)
82 {
83 printf("│");
84 for(col = 0;col < COLLEN;col++)
85 {
86 switch(cell[row][col])
87 {
88 case ALIVE: printf("●│");
89 break;
90 case DEAD: printf("○│");
91 break;
92 default:
93 ;
94 }
95 }
96 printf("\n");
98 if(row < ROWLEN - 1)
99 {
100 printf("├");
101 for(col = 0;col < COLLEN - 1;col++)
102 {
103 printf("──┼");
104 }
105 printf("──┤\n");
106 }
107 }
108 printf("└");
109 for(col = 0;col < COLLEN - 1;col++)
110 {
111 printf("──┴");
112 }
113 printf("──┘\n");
114 }
116 void cellfun()
117 {
118 int row,col,sum;
119 int count = 0;
121 for(row = 0; row < ROWLEN;row ++)
122 {
123 for(col = 0;col < COLLEN;col++)
124 {
125 switch(LinSum(row,col))
126 {
127 case 2: celltemp[row][col] = cell[row][col];
128 break;
129 case 3: celltemp[row][col] = ALIVE;
130 break;
131 default: celltemp[row][col] = DEAD;
132 }
133 }
134 }
135 for(row = 0;row < ROWLEN;row++)
136 {
137 for(col = 0;col < COLLEN;col++)
138 {
139 cell[row][col] = celltemp[row][col];
140 }
141 }
142 for(row = 0;row < ROWLEN;row++)
143 {
144 for(col = 0;col < COLLEN;col++)
145 {
146 if(cell[row][col] == ALIVE)
147 {
148 count++;
149 }
150 }
151 }
152 sum = count;
153 OutCell();
154 printf("当前状态下,共有%d个活细胞。\n",sum);
155 }
157 int main()
158 {
159 char again;
160 printf("生命游戏!\n");
161 initcell();
162 OutCell();
163 printf("按任意键开始游戏,进行细胞转换。\n");
164 getch();
165 S1: cellfun();
166 S2: printf("\n继续生产下一次细胞的状态(y/n)?");
167 fflush(stdin);
168 scanf("%c",&again);
169 if(again == 'Y' || again == 'y')
170 {
171 goto S1;
172 }
173 else if(again == 'n' || again == 'N')
174 {
175 goto S3;
176 }
177 else
178 {
179 printf("输入错误,请重新输入!\n");
180 goto S2;
181 }
182 S3: printf("游戏结束!\n");
184 return 0;
185 }
ms sql server支持的游标类型 sql游标使用
数据库开发过程中,当你检索的数据只是一条记录时,你所编写的事务语句代码往往使用SELECT INSERT 语句。但是我们常常会遇到这样情况,即从某一结果集中逐一地读取一条记录。那么如何解决这种问题呢?游标为我们提供了一种极为优秀的解决方案。
1.1 游标和游标的优点
在数据库中,游标是一个十分重要的概念。游标提供了一种对从表中检索出的数据进行操作的灵活手段,就本质而