Task: heritage
Lang: C ++
Compiling...
Compile: OK
Executing...
Test 1: Test OK [0.000 secs, 3020 KB]
Test 2: Test OK [0.000 secs, 3020 KB]
Test 3: Test OK [0.000 secs, 3020 KB]
Test 4: Test OK [0.000 secs, 3020 KB]
Test 5: Test OK [0.000 secs, 3020 KB]
Test 6: Test OK [0.000 secs, 3020 KB]
Test 7: Test OK [0.000 secs, 3020 KB]
Test 8: Test OK [0.000 secs, 3020 KB]
Test 9: Test OK [0.000 secs, 3020 KB]
All tests OK.
1 /*
2 Prog: heritage
3 ID: jiafeim1
4 Lang: C ++
5 */
6
7 # Include < Stdio. h >
8 # Include < String . H >
9 Char Pre [ 35 ];
10 Char Mid [ 35 ];
11 Int Len, cur;
12 File * Fin, * Fout;
13 Void Work ( Int Pres, Int Pree, Int Mids, Int Mide)
14 {
15 If (MIDS = Mide)
16 {
17 Fprintf (fout, " % C " , Mid [mids]);
18 Return ;
19 }
20 Int Root;
21 For ( Int I = Mids; I <= Mide; ++ I)
22 {
23 If (Pre [pres] = Mid [I])
24 {
25 Root = I;
26 Break ;
27 }
28 }
29 If (MIDS <= Root - 1 )
30 Work (PRES + 1 , Pres + Root - Mids - 1 , Mids, Root - 1 );
31 If (Mide > = Root + 1 )
32 Work (PRES + Root - Mids + 1 , Pres + Root - Mids + Pree - Root, root + 1 , Mide );
33 Fprintf (fout, " % C " , Mid [root]);
34 }
35
36
37 Int Main ()
38 {
39 Fin = Fopen ( " Heritage. In " , " R " );
40 Fout = Fopen ( " Heritage. Out " , " W " );
41
42 Cur = 0 ;
43 Fscanf (FIN, " % S " , Mid );
44 Fscanf (FIN, " % S " , Pre );
45 Len = Strlen (pre );
46
47 Work ( 0 , Len - 1 , 0 , Len - 1 );
48
49 Fprintf (fout, " \ N " );
50
51 Fclose (FIN );
52 Fclose (fout );
53 Return 0 ;
54 }