Array-12. Simple connection, array-12 connection
1/* 2 * Main. c 3 * E12-array-12. simple connection: 4 * Created on: August 22, 2014 5 * Author: boomkeeper 6 ********* passed the test *********** 7 */8 9 # include <stdio. h> 10 # include <stdlib. h> 11 12 int main (void) {13 14 int x1, y1, x2, y2; 15 int I, j, k; 16 int N; // N17 char array [10] [10]; 18 int count = 0; // the number of times a match is incorrect 19 int m = 0; // The number of times the player inputs 20 int letterLeft; // The number of remaining letters in the disk. If the number is reduced to 0, the player wins 21 22 scanf ("% I", & N ); 23 getchar (); 24 25 letterLeft = 2 * N * 2 * N; 2 6 27 for (I = 0; I <(2 * N); I ++) 28 for (j = 0; j <(2 * N); j ++) {29 array [I] [j] = getchar (); 30 getchar (); 31} 32 33 scanf ("% d", & m); 34 getchar (); 35 36 for (I = 0; I <m; I ++) {37 scanf ("% d", & x1, & y1, & x2, & y2); 38 39 // matched successfully, remove the two symbols as '*' 40 if (array [x1-1] [y1-1] = array [x2-1] [y2-1]) & 41 (array [x1-1] [y1-1] <= 'Z' & array [x1-1] [y1-1]> = 'A ')) {42 array [x1-1] [y1-1] = '*'; 43 array [x2-1] [y2-1] = '*'; 44 letterLeft = letterLeft-2; 45 46} e Lse {47 printf ("Uh-oh \ n"); 48 count ++; 49 continue; 50} 51 // If the matching error reaches 3 times, output "Game Over" and end the Game 52 if (count = 3) {53 printf ("Game Over \ n"); 54 exit (0 ); 55} 56 // when all the symbols match successfully, the output is "Congratulations! ", Then end the game 57 if (letterLeft = 0) {58 printf ("Congratulations! \ N "); 59 exit (0); 60} 61 // output disc 62 for (j = 0; j <2 * N; j ++) {63 for (k = 0; k <2 * N-1; k ++) 64 printf ("% c", array [j] [k]); 65 printf ("% c \ n", array [j] [2 * N-1]); 66} 67 68} 69 70 return 0; 71}
I just saw that this topic was too big. It was simply a short article reading and understanding, so many words... all of a sudden, no patience.
But finally, it was much simpler than "array-11. Monkey King Election", because it did not involve a very profound mathematical problem, as long as it was able to withstand the child, it was still done.
I only read the questions three or four times and tested the questions dozens of times. If this is true in the exam... %> _ <% >_< %> _ <%
Question link:
Http://pat.zju.edu.cn/contests/basic-programming/%E6%95%B0%E7%BB%84-12
.
Written in C language, converts a [3] [4] z to a one-dimensional array B [12]
According to the comrades on the second floor.
If you want to convert it, you can use the following:
Int a [3] [3];
Int B [12];
Int t = 0;
For (I = 0; I <3; I ++ ){
For (j = 0; I <4; j ++ ){
B [t ++] = a [I] [j];
}
}
Given an array: int [] array = {121,565,}; print the elements in ascending order.
# Include <stdio. h>
Void paixu (int x [], int n)/* parameters are referenced by array x [] and subscript. */
{Int I, j, k, t;
For (I = 0; I <n-1; I ++)/* obtain the baseline number. I = 1 -- N-1 (currently ranking champion I --> k )*/
{
For (k = I, j = I + 1; j <n; j ++)/* obtain the comparison number j = I + 1 -- n (competitor --> j) */
If (x [j] <x [k]) k = j;/* determine the k-th name (Contest: if the opponent <the defender, record j --> k */
If (k! = I) t = x [I], x [I] = x [k], x [k] = t;/* I! = K no. I exchanges with the number in k. */
}
For (I = 0; I <n; I ++)
Printf ("% d \ t", x [I]);
}
Void main ()/*** main function *** value assignment and output ***/
{
Int a [] = {121,565,}, n = 6;/* n = Data Count */
Paixu (a, n );
Getchar ();/* pause */
}