Given a nest structure, let's simulate beebot production. N Bees produce 26 types of honey and specify to produce honey in a certain column. Once the honey is produced in a certain column, the honey runs from the top to the bottom. If the column is full, it will never be installed. If the following types of honey are the same, a candy is generated. How many candy can be produced at the end?
Solution: simply simulate a question. First, create a table for the honeycomb structure, and then use the stack to simulate each input, finally, the output is a honeycomb with honey.
Test data: 14
EA
EB
EC
ED
EE
EF
EG
EH
EI
EJ
EK
EK
EG
EL
11
EA
EA
EA
EA
EA
EA
EA
EA
EA
EA
EA
11
DA
DA
DA
DA
DA
DA
DA
DA
DA
DA
DA
11
IA
IA
IA
IA
IA
IA
IA
IA
IA
IA
IA
Code:
[Csharp]
# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>
Int st [40] [40];
Int top [40], n, m, ans;
Char candy [11000];
Char hive [40] [40];
Char ori [40] [40] = {
"",
"_",
"_/\\_",
"_/\\_/\\_",
"_/\\_/\\_/\\_",
"_/\\_/\\_/\\_/\\_",
"/\\_/\\_/\\_/\\_/\\",
"\\_/\\_/\\_/\\_/\\_/",
"/\\_/\\_/\\_/\\_/\\",
"\\_/\\_/\\_/\\_/\\_/",
"/\\_/\\_/\\_/\\_/\\",
"\\_/\\_/\\_/\\_/\\_/",
"/\\_/\\_/\\_/\\_/\\",
"\\_/\\_/\\_/\\_/\\_/",
"/\\_/\\_/\\_/\\_/\\",
"\\_/\\_/\\_/\\_/\\_/",
"/\\_/\\_/\\_/\\_/\\",
"\\_/\\_/\\_/\\_/\\_/",
"/\\_/\\_/\\_/\\_/\\",
"\\_/\\_/\\_/\\_/\\_/",
"\\_/\\_/\\_/\\_/",
"\\_/\\_/\\_/",
"\\_/\\_/",
"\\_/",
};
Int main ()
{
Int I, j, k, tpcol, tp, colsum;
While (scanf ("% d", & n )! = EOF ){
Ans = 0;
Memcpy (hive, ori, sizeof (ori ));
Memset (top, 0, sizeof (top ));
For (I = 0; I <n; ++ I ){
Scanf ("% s", candy );
Tpcol = (candy [0]-'A' + 1) * 2-1;
Colsum = 11-abs (9-tpcol)/2;
Tp = candy [1]-'A ';
// Use stack operations to simulate the computing of candy count
If (top [tpcol] = 0 ){
Top [tpcol] ++;
St [tpcol] [top [tpcol] = tp;
}
Else if (top [tpcol] <colsum ){
If (st [tpcol] [top [tpcol] = tp)
Top [tpcol] --, ans ++;
Else st [tpcol] [++ top [tpcol] = tp;
}
}
Printf ("The number of candy is % d. \ n", ans );
// Change the content of the peak nest
For (I = 1; I <= 17; I + = 2) {// column
Int tpmin = 2 + abs (I-9)/2;
Int tpmax = 22-abs (I-9)/2;
For (k = 1, j = tpmax; k <= top [I]; j-= 2, ++ k)
Hive [j] [I] = st [I] [k] + 'a'; // printf ("% d \ n", j, I ),
}
For (I = 1; I <= 23; ++ I)
Printf ("% s \ n", hive [I]);
} Www.2cto.com
}
Author: woshi250hua