1. "The results are in the blanks" (5 points)
The National Day of 1949 (October 1) is Saturday.
The National Day of the Year (2012) is Monday.
So, from the founding of the present, how many times the National day is just Sunday?
As long as the answer, unlimited means!
You can use Windows Calendar, Windows Calculator, Excel formulas, .....
Of course, you can also program!
Do not ask to write exactly what year, as long as a number!
Never submit the source code!
The answer should not be written here, in the "answer. txt"
Direct Excel Weekday function water a bit ...
2. "Code in the Blanks" (16 points)
An industrial monitoring device constantly sends back sampled data. Each data is an integer (between 0 and 1000). Each data is separated by white space characters (spaces, tab, or carriage return). This data is stored as text in the file.
Because most of the time the adjacent sampling interval data is the same, you can use this feature to do data compression storage. The method is: to N (n>1) consecutive same number records only N and the number itself, to M (m>0) consecutive non-repeating number, then the record m*-1 and the numbers themselves (the reason is to use a negative number, is to distinguish from the first case, easy to decompress).
Example: Sample numbers:
12 34 34 25 25 25 25 11 15 17 28 14 22 22 22 13
According to the above rule changes:
-1 12 2 34 4 25-5 11 15 17 28 14 3 22-1 13
The following program implements this function. Please read the analysis code carefully and fill in the blank section.
void pop (int s, int* buf, int c, file* FP)
{
int i;
if (s)
{
fprintf (FP, "%d%d", C, *buf);
}
Else
{
fprintf (FP, "%d",-c);
for (i=0; i<c; i++)
{
fprintf (FP, "%d", buf[i]);
}
}
}
void Dopack (file* R, file* W)
{
int buf[buf_n];
int pos = 0; Where the next number will be stored in the BUF
int c = 0; The number of integers that the current segment has been read into
int PST;
int CST;
while (FSCANF (R, "%d", Buf+pos) ==1)
{
if (c==0)
{
c = pos = 1;
Continue
}
if (c==1)
{
PST = buf[0] = = buf[1];
pos = pos + 1-pst;
c = 2;
Continue
}
CST = buf[pos-1] = = Buf[pos];
if (PST &&!CST)
{
Pop (PST, BUF, C, W);
Buf[0] = buf[1];
c = pos = 1;
PST = CST;
}
else if (!pst && CST | | pos = = buf_n-1)
{
Pop (PST, BUF, C-1, W);
Buf[0] = buf[pos-1];
c = 2;
if (!CST)
{
BUF[1] = Buf[pos];
pos = 2;
}
Else
{
pos = 1;
PST = ______________; Fill in the blanks 1
}
}
Else
{
C + +;
if (!pst) pos++;
}
}//While
if (c>0) _____________________________; Fill in the Blanks 2
}
void Main ()
{
File* RFP;
file* WFP;
if ((Rfp=fopen (Rfile, "R")) = = = NULL)
{
printf ("Can not open%s!\n", rfile);
Exit (1);
}
if ((Wfp=fopen (Wfile, "w")) = = = NULL)
{
printf ("Can not open%s!\n", wfile);
Fclose (RFP);
Exit (2);
}
Dopack (RFP, WFP);
Fclose (WFP);
Fclose (RFP);
}
Note
Just fill in the missing parts and don't copy the existing code.
The code is not more than 1 statements (the sentence will not contain a semicolon)
The length of the code is no more than 256 characters.
The answer is written in the "answer. txt", do not write here!
Answer: PST = CST; Pop (PST, BUF, C, W);
3. "Programming Questions" (out of 19)
In many software, you can quickly locate an entry by typing the first letter of the phonetic alphabet. For example, in the railway ticketing software, enter: "BJ" can be located to "Beijing." How do you implement this functionality in your own software? The crux of the problem is that each Chinese character must be able to calculate its phonetic initials.
In the GB2312 Chinese character coding way, 3,755 of the first-level Chinese characters are arranged in pinyin order. We can use this feature to find the first letter of pinyin for commonly used Chinese characters.
The GB2312 encoding scheme uses two bytes per kanji. The first byte is the area code, and the second byte is the offset number in the zone. In order to be compatible with existing ASCII encodings (in both Latin and Western), the area code and offset numbers begin with 0XA1.
We just need to find the pinyin a,b,c,... X, y, z each letter corresponds to the GB2312 encoded first character, you can locate all first-level Chinese characters Pinyin initials (regardless of the polyphone situation). The above information is given in the table below. Please use this table to write a program to find out the pinyin initials of commonly used Chinese characters.
A ah, b0a1.
b Pattaya b0c5
C Rub b2c1
D-Lap B4ee
E Moth B6ea
F FA b7a2
G-Karma B8C1
H ha b9fe
J Hit BBF7
K Kerala BFA6
L C0AC
M mom C2e8
N Take c4c3
o Oh c5b6
P PA c5be
Q-Period C6da
R C8BB
S Isaac C8f6
T collapsed CBFA
W Dig CDDA
X-CEF4
Y-Pressure d1b9
Z-Turns D4D1
"Input, output format requirements"
The user enters an integer n (n<100) First, indicating that there will be n lines of text next. Then enter the N-line string (no more than 50 Chinese characters per string).
The program outputs n lines, each line content is the first letter of the Chinese character of the corresponding line entered by the user.
No spaces between letters, all uppercase letters.
For example:
User input:
3
Everyone loves science.
Beijing Tiananmen Square
Software Contest
The program output:
Djakx
Bjtamgc
Rjds
Note
Please carefully debug! Your program only has the chance to score when it can run the correct results!
The input data used in the grading is probably different from the instance data given in the quiz paper.
Please write all the functions in the same file, after debugging, copy to the "Candidates folder" corresponding to the "answer. txt" in the title.
The relevant engineering documents should not be copied into.
Sources such as drawing, Win32API, interrupt calls, hardware operations, or operating system-related APIs cannot be used in source code.
STL class libraries are allowed, but not the class libraries of non-ANSI C + + standards such as MFC or ATL.
For example, you cannot use the CString type (which belongs to the MFC class Library), you cannot use the randomize, the random function (not part of the ANSI C + + standard)
#include <cstdio> #include <iostream>using namespace Std;int table[27] = {0xb0a1,0xb0c5,0xb2c1,0xb4ee, 0xb6ea,0xb7a2,0xb8c1,0xb9fe,0xbbf7,0xbbf7,0xbfa6,0xc0ac,0xc2e8,0xc4c3,0xc5b6,0xc5be,0xc6da,0xc8bb,0xc8f6, 0xcbfa,0xcdda,0xcdda,0xcdda,0xcef4,0xd1b9,0xd4d1,0xffff};//Note that there is no pinyin in the beginning of the i,u,v (because the pinyin does not start with the i,u,v), so the next value can be replaced, The last boundary is replaced by the maximum value int search (int p) {for (int i = 0; i < ++i) if (Table[i] > P) {return i-1; }}int Main () {int T; Char buf[110]; scanf ("%d", &t); while (t--) {scanf ("%s", buf); int len = strlen (BUF);//A Kanji account of two bytes for (int i = 0; i < len; i+=2) {int tmp1 = 0X000000FF & Buf[i]; Take the first byte because the Temp1 is a 32-bit integer, so just remove its low eight bits. int tmp2 = 0X000000FF & buf[i+1]; Takes a second byte. The int pos = search (tmp1*0x100 + TMP2);//Group composition is encoded in the encoding table. printf ("%c", ' A ' +pos); } printf ("\ n"); }//while (1); return 0;}
4. "Programming Questions" (out of 27)
DNA, which is commonly said, is a kind of biological macromolecules with genetic information. It consists of 4 major deoxidation nucleotides (damp, DGMP, DCMT and dTMP) connected by a phosphate ester bond. These 4 nucleotides can be separately recorded as: A, G, C, T.
The genetic information carried by DNA can be used in the form of: Aggtcgactcca .... The string to be represented. DNA may have random deviations during transcription, which ultimately results in a diversity of organisms.
To simplify the problem, we assume that the possible deviations of DNA at the time of replication are (theoretically, deviations may occur for each base being copied):
1. Drain off a certain deoxidation nucleotide. For example, copy the AGGT into: AGT
2. The wrong code, such as the AGGT copied into: AGCT
3. Re, such as the AGGT copy: AAGGT
If a DNA string A is at least n times wrong to become a DNA string B, the distance of the two DNA strings is n.
For example: the distance between AGGTCATATTCC and CGGTCATATTC is 2
Your task is: to write a program to find the distance of two DNA strings.
"Input, output format requirements"
The user enters the integer n (n<100) First, indicating that there is a 2n row of data next.
The next 2n line of input represents a set of pairs of DNA per 2 rows. (data length per line <10000)
The program outputs n lines, indicating the distance of the N group of DNA.
For example: User input:
3
Agctaaggcctt
Agctaaggcct
Agctaaggcctt
Aggctaaggcctt
Agctaaggcctt
Agcttaaggctt
The program should output:
1
1
2
Note
Please carefully debug! Your program only has the chance to score when it can run the correct results!
The input data used in the grading is probably different from the instance data given in the quiz paper.
Please write all the functions in the same file, after debugging, copy to the "Candidates folder" corresponding to the "answer. txt" in the title.
The relevant engineering documents should not be copied into.
Sources such as drawing, Win32API, interrupt calls, hardware operations, or operating system-related APIs cannot be used in source code.
STL class libraries are allowed, but not the class libraries of non-ANSI C + + standards such as MFC or ATL.
For example, you cannot use the CString type (which belongs to the MFC class Library), you cannot use the randomize, the random function (not part of the ANSI C + + standard)
We can define a two-dimensional array dp[i][j] to represent the state, Dp[i][j] the shortest distance of the substring b[1....m] of the substring a[1...i] and B[1...J] of A[1...N], that is, B[1...J] how many operations (increment, delete, Modified) can be changed to A[1..I].
State transition equation:
There are three situations where the status of the above design can be shifted. We will now look at A[i] and B[j], ①, we can insert a nucleotide (i.e. a character) behind B[j] ch,ch==a[i], in this case, at least dp[i-1][j] + 1 steps, i.e. dp[i][j] = Dp[i-1][j] + 1. ②, we can delete b[j], so that B[1...J] becomes a[1...i] requires dp[i][j-1] step, i.e. dp[i][j] = Dp[i][j-1] + 1. ③, we can also consider modifying b[j], make it into a[j], but if B[J] is originally equal to a[i], then the modification is actually equivalent to using 0 steps, if B[J]! = A[i], then the change is equivalent to 1 steps. So dp[i][j] = Dp[i-1][j-1] + (a[i] = = B[j]? 0, 1).
Decision:
The decision is simple, select a minimum value from the above three state transitions.
Processing boundary:
It is very important to deal with the boundary, it should be noted that the initialization of dp[0][0....m],dp[0.....n][0], so to see, Dp[0][i], that is A[1...N] is an empty string, and B[1...M] 10 strings of length I, It is clear that the B-string becomes a-string to remove the I nucleotide. DP[0....N][0] How to initialize, everyone think about it, the truth is the same.
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include < algorithm>using namespace Std;const int maxn = 10100;int Dp[maxn][maxn];char NW[MAXN], old[maxn];int main (void) {Fre Open ("In.txt", "R", stdin); int n; scanf ("%d", &n); for (int i = 0; i < n; i + +) {scanf ("%s%s", old, NW); int len1 = strlen (old); int len2 = strlen (NW); for (int j = 0; J <= Len2; j + +) dp[j][0] = j; for (int j = 0; J <= Len1; j + +) dp[0][j] = j; for (int j = 1; J <= Len2; j + +)//new {for (int JJ = 1; JJ <= Len1; JJ + +)//old { if (old[jj] = = Nw[j]) dp[j][jj] = min (min (dp[j][jj-1] + 1/*delete*/, DP[J-1][JJ] + 1/*copy* /), dp[j-1][jj-1]); else DP[J][JJ] = min (dp[j][jj-1] + 1, dp[j-1][jj-1] + 1); Delete or modify} printf ("%d\n", Dp[len2][len1]); } return 0;}
5. "Programming Questions" (out of 33)
"Sudoku" is now a hot game of intelligence. It is generally believed that its origins are "Latin squares", which were invented by the great mathematician Euler in 1783.
[1.jpg] Shown: 6x6 's small lattice is divided into 6 parts (the figure is distinguished by different colors), each part contains 6 small lattice (hereinafter also known as a grouping).
At the beginning, some of the cells have been filled with letters (one of abcdef). The letters need to be filled in all the remaining small Gezen.
When all is completed, the following constraints must be met:
1. The letters are only allowed to be one of the a,b,c,d,e,f.
2. The letters in each of the 6 cells in each row cannot be duplicated.
3. In each of the 6 small cells in the column, the letters you fill cannot be duplicated.
4. Each grouping (see different colors in the figure) contains 6 small cells, the letters written cannot be duplicated.
In order to express the convenience, we use the following 6-order square matrix to represent the corresponding grouping of the figure [1.jpg] (group number is 0~5):
000011
022013
221113
243333
244455
445555
Use the following data to indicate the completion of their existing letters:
02C
03B
05A
10g
35E
53F
Obviously, the first column represents the row number, the second column represents the column number, and the third column represents the letter filled in. The line number and column number are calculated starting from 0.
A workable completion scheme (the only answer to this question) is:
E F C B D A
A C E D F B
D A B E C F
F B D C A E
B D F A E C
C E A F B D
Your task is: Write the program, solve the general problem of Latin squares, if multiple solutions, ask to find all the solutions.
"Input, output format requirements"
The user first enters 6 rows of data, indicating the grouping of Latin squares.
The user then enters an integer n (n<36) that represents the next number of rows of data
Then enter n rows of data, each line representing a pre-filled letter.
The program outputs all possible solutions (the order of each solution is not important).
Each solution occupies 7 rows.
That is, the output of an integer, representing the number of the solution (starting from 1), and then output a 6x6 of the letter matrix, representing the solution.
The letters of the solution are separated by a space.
If no solution is found that satisfies the condition, the output is "no solution"
For example: User input:
000011
022013
221113
243333
244455
445555
6
02C
03B
05A
10g
35E
53F
The program output:
1
E F C B D A
A C E D F B
D A B E C F
F B D C A E
B D F A E C
C E A F B D
Again, user input:
001111
002113
022243
022443
544433
555553
7
04B
05A
23g
14C
24E
50C
51A
The program output:
1
D C E F B A
E F A D C B
A B F C E D
B E D A F C
F D C B A E
C A B E D F
2
D C E F B A
E F A D C B
A D F B E C
B E C A F D
F B D C A E
C A B E D F
3
D C F E B A
A E B D C F
F D A C E B
B F E A D C
E B C F A D
C A D B F E
4
D C F E B A
B E A D C F
A D C F E B
F B E A D C
E F B C A D
C A D B F E
5
D C F E B A
E F A D C B
A B C F E D
B E D A F C
F D B C A E
C A E B D F
6
D C F E B A
E F A D C B
A B D F E C
B E C A F D
F D B C A E
C A E B D F
7
D C F E B A
E F A D C B
A D B F E C
B E C A F D
F B D C A E
C A E B D F
8
D C F E B A
F E A D C B
A D B C E F
B F E A D C
E B C F A D
C A D B F E
9
D C F E B A
F E A D C B
A F C B E D
B D E A F C
E B D C A F
C A B F D E
Note
Please carefully debug! Your program only has the chance to score when it can run the correct results!
The input data used in the grading is probably different from the instance data given in the quiz paper.
Please write all the functions in the same file, after debugging, copy to the "Candidates folder" corresponding to the "answer. txt" in the title.
The relevant engineering documents should not be copied into.
Sources such as drawing, Win32API, interrupt calls, hardware operations, or operating system-related APIs cannot be used in source code.
STL class libraries are allowed, but not the class libraries of non-ANSI C + + standards such as MFC or ATL.
For example, you cannot use the CString type (which belongs to the MFC class Library); For example, you cannot use randomize, the random function (not part of the ANSI C + + standard)
#include <cstdio>//Use the advantage of playing table #include<iostream>using namespace Std;int count=0; There are still a few empty blanks. Char map[6][6]={0};//storage result, 0 indicates that the current position in the result matrix is not filled with an int row[6]={0},col[6]={0};//statistic row, the number of elements in the column bool fillgro[6][6]={0} ; FILLGROG[I][J] Indicates whether the ' A ' +j in the group grouped as I has used a char group[6][7];//record input When the grouping case is int. = 0; Record result number void OutPut () {printf ("%d\n", ++case); for (int. i=0;i<6;i++) {for (int j=0; j<5; j + +) printf ("%c", Map[i][j]); printf ("%c\n", map[i][5]); }} void Searcher () {int i,j,k,max,x,y; BOOL F[6]={0}; if (count==36) {outPut (); Return } count++; Max=-1;//Find the best location---that is, the coordinates that are not currently filled are the sum of the rows and columns of the column, for (i=0;i<6;i++) {if (row[i]==6)//The current row is filled Conti Nue for (j=0;j<6;j++) if (map[i][j]==0 && (Row[i]+col[j]) >max) {//each time you find the sum of the rows and columns in the current coordinate, fill in the first MAX=ROW[I]+COL[J]; X=i; Y=j; }//Search All can be filled in the best location (The allowable value of x, y) for (k=0;k<6;k++) {if (map[x][k]) f[map[x][k]-' A '] = true;/if (Map[k][y] ) f[map[k][y]-' A '] = true; if (fillgro[group[x][y]-' 0 '][k])//k corresponding character (' A ' +k) f[k]=true; } row[x]++; col[y]++;//the current row and column are incremented by one for (k=0;k<6;k++) if (f[k]==false) {map[x][y] = ' A ' +k; fillgro[group[x][y]-' 0 '][k] = true; Searcher (); fillgro[group[x][y]-' 0 '][k] = false; Backtracking}//backtracking row[x]--;//restore before adding the scene col[y]--; Map[x][y] = 0;//The count--is not filled in the restore diagram; } int main () {char C; int n,i,j; for (i=0;i<6;i++) scanf ("%s", Group[i]); scanf ("%d", &n); c = GetChar (); for (; n; n--) {I=getchar ()-' 0 '; J=getchar ()-' 0 '; C=getchar ();//mode novel map[i][j] = C; count++; row[i]++; col[j]++; fillgro[group[i][j]-' 0 '][c-' A '] = true; GetChar ();//Absorbing Enter } searcher (); return 0; }
Blue Bridge Cup third finals