晚上有同学找我要题解,我就干脆做了一下题目,希望能有些帮助。
1/**//*
2Copyright (C) 2012, coreBugZJ, all rights reserved.
3
42012-03-07 ECNU 编程实践考试
5*/
6
7
8/**//************************************************************
9四元一次方程
10枚举即可
11*/
12/**//*
13#include <stdio.h>
14#include <string.h>
15
16#define L 1003
17
18int solve( int n ) {
19 int w, x, y, ans = 0;
20
21 for ( w = 0; 4*w <= n; ++w ) {
22 for ( x = 0; 4*w+3*x <= n; ++x ) {
23 for ( y = 0; 4*w+3*x+2*y <= n; ++y ) {
24 ++ans;
25 }
26 }
27 }
28
29 return ans;
30}
31
32int main() {
33 int t, n;
34 scanf( "%d", &t );
35 while ( t-- > 0 ) {
36 scanf( "%d", &n );
37 printf( "%d\n", solve(n) );
38 }
39 return 0;
40}
41*/
42
43
44/**//************************************************************
45Search Web Pages
46排序即可
47*/
48/**//*
49#include <stdio.h>
50#include <string.h>
51
52#define L 103
53#define N 23
54
55struct __Node
56{
57 char url[ L ];
58 int vi;
59};
60typedef struct __Node Node;
61
62Node node[ N ];
63
64int main() {
65 int n, i, j;
66 Node tmp;
67
68 scanf( "%d", &n );
69 for ( i = 0; i < n; ++i ) {
70 scanf( "%s%d", node[ i ].url, &(node[ i ].vi) );
71 }
72
73 for ( i = 0; i < n; ++i ) {
74 for ( j = i+1; j < n; ++j ) {
75 if ( node[ i ].vi < node[ j ].vi ) {
76 tmp = node[ i ];
77 node[ i ] = node[ j ];
78 node[ j ] = tmp;
79 }
80 }
81 }
82
83 for ( i = 0; i < n; ++i ) {
84 if ( node[ i ].vi == node[ 0 ].vi ) {
85 puts( node[ i ].url );
86 }
87 }
88
89 return 0;
90}
91*/
92
93
94/**//************************************************************
95整数的质因子分解
96素数筛法
97*/
98/**//*
99#include <stdio.h>
100#include <string.h>
101
102#define N 20003
103
104int prime[ N ], nprime;
105
106void init() {
107 int i, j;
108 memset( prime, 0, sizeof(prime) );
109 nprime = 0;
110 for ( i = 2; i < N; ++i ) {
111 if ( 0 == prime[ i ] ) {
112 prime[ nprime++ ] = i;
113 for ( j = i+i; j < N; j+=i ) {
114 prime[ j ] = 0;
115 }
116 }
117 }
118}
119
120void solve( int a ) {
121 int i, p, e;
122 i = 0;
123 while ( 1 < a ) {
124 p = prime[ i ];
125 e = 0;
126 while ( a % p == 0 ) {
127 ++e;
128 a /= p;
129 }
130 if ( 0 < e ) {
131 printf( "(%d,%d)", p, e );
132 }
133 ++i;
134 }
135 printf( "\n" );
136}
137
138int main() {
139 int t, a;
140 init();
141 scanf( "%d", &t );
142 while ( t-- > 0 ) {
143 scanf( "%d", &a );
144 solve( a );
145 }
146 return 0;
147}
148*/
149
150
151/**//************************************************************
152行数据的排序
153逆字典序排序
154注意 0≤ai≤109 中 109 表示 10 的 9 次方!
155*/
156/**//*
157程序二
158*/
159/**//*
160#include <stdio.h>
161#include <stdlib.h>
162
163#define N 1003
164#define L 53
165
166int num[ N ][ L ];
167
168int cmp( const void *a, const void *b ) {
169 int *x = (int*)a;
170 int *y = (int*)b;
171 int i;
172 for ( i = 0; (-1!=x[i])&&(-1!=y[i]); ++i ) {
173 if ( x[ i ] > y[ i ] ) {
174 return -1;
175 }
176 if ( x[ i ] < y[ i ] ) {
177 return 1;
178 }
179 }
180 if ( (-1 == x[i]) && (-1 == y[i]) ) {
181 return 0;
182 }
183 if ( -1 == y[ i ] ) {
184 return -1;
185 }
186 return 1;
187}
188
189int main() {
190 int t, n, a, i, j;
191 scanf( "%d", &t );
192 while ( t-- > 0 ) {
193 scanf( "%d", &n );
194 for ( i = 0; i < n; ++i ) {
195 a = 1;
196 for ( j = 0; -1 != a; ++j ) {
197 scanf( "%d", &a );
198 num[ i ][ j ] = a;
199 }
200 }
201
202 qsort( num, n, sizeof(num[0]), cmp );
203
204 for ( i = 0; i < n; ++i ) {
205 if ( -1 != num[ i ][ 0 ] ) {
206 printf( "%d", num[ i ][ 0 ] );
207 for ( j = 1; num[ i ][ j ] != -1; ++j ) {
208 printf( " %d", num[ i ][ j ] );
209 }
210 }
211 printf( "\n" );
212 }
213 }
214 return 0;
215}
216*/
217
218/**//*
219程序一,WA 了,因为 109 !!
220*/
221/**//*
222#include <stdio.h>
223#include <string.h>
224#include <stdlib.h>
225
226#define N 1003
227#define L 53
228#define BASE 5
229
230char num[ N ][ L ];
231
232int cmp( const void *a, const void *b ) {
233 return strcmp( ((const char *)b), ((const char*)a) );
234}
235
236int main() {
237 int t, n, a, i, j;
238 scanf( "%d", &t );
239 while ( t-- > 0 ) {
240 scanf( "%d", &n );
241 for ( i = 0; i < n; ++i ) {
242 for ( j = 0; ;++j ) {
243 scanf( "%d", &a );
244 if ( -1 != a ) {
245 num[ i ][ j ] = (char)(a+BASE);
246 }
247 else {
248 num[ i ][ j ] = '\0';
249 break;
250 }
251 }
252 }
253
254 qsort( num, n, sizeof(num[0]), cmp );
255
256 for ( i = 0; i < n; ++i ) {
257 if ( '\0' != num[ i ][ 0 ] ) {
258 printf( "%d", (int)(num[ i ][ 0 ]) - BASE );
259 for ( j = 1; num[ i ][ j ] != '\0'; ++j ) {
260 printf( " %d", (int)(num[ i ][ j ]) - BASE );
261 }
262 }
263 printf( "\n" );
264 }
265 }
266 return 0;
267}
268*/
269
270
271/**//************************************************************
272Phone Number
273模拟,字符串排序
274*/
275/**//*
276#include <stdio.h>
277#include <string.h>
278#include <stdlib.h>
279
280#define N 103
281#define L 10
282#define LM 89
283#define CM 256
284
285char num[ N ][ L ];
286int n;
287
288char* map[ CM ];
289
290void init() {
291 int i;
292 for ( i = 0; i < CM; ++i ) {
293 map[ i ] = "";
294 }
295
296 map[ '0' ] = "0";
297 map[ '1' ] = "1";
298 map[ '2' ] = map[ 'A' ] = map[ 'B' ] = map[ 'C' ] = "2";
299 map[ '3' ] = map[ 'D' ] = map[ 'E' ] = map[ 'F' ] = "3";
300 map[ '4' ] = map[ 'G' ] = map[ 'H' ] = map[ 'I' ] = "4";
301 map[ '5' ] = map[ 'J' ] = map[ 'K' ] = map[ 'L' ] = "5";
302 map[ '6' ] = map[ 'M' ] = map[ 'N' ] = map[ 'O' ] = "6";
303 map[ '7' ] = map[ 'P' ] = map[ 'Q' ] = map[ 'R' ] = map[ 'S' ] = "7";
304 map[ '8' ] = map[ 'T' ] = map[ 'U' ] = map[ 'V' ] = "8";
305 map[ '9' ] = map[ 'W' ] = map[ 'X' ] = map[ 'Y' ] = map[ 'Z' ] = "9";
306}
307
308int cmp( const void *a, const void *b ) {
309 return strcmp( (char*)a, (char*)b );
310}
311
312int main() {
313 int i, j;
314 char tmp[ LM ];
315
316 init();
317
318 scanf( "%d", &n );
319 for ( i = 0; i < n; ++i ) {
320 num[ i ][ 0 ] = '\0';
321
322 scanf( "%s", tmp );
323 for ( j = 0; tmp[ j ]; ++j ) {
324 strcat( num[ i ], map[ tmp[ j ] ] );
325 if ( 4 == strlen( num[ i ] ) ) {
326 strcat( num[ i ], "-" );
327 }
328 }
329 }
330
331 qsort( num, n, sizeof(num[0]), cmp );
332
333 strcpy( num[ n ], "*" );
334 j = 1;
335 for ( i = 0; i < n; ++i ) {
336 if ( 0 != strcmp( num[i], num[i+1] ) ) {
337 printf( "%s %d\n", num[i], j );
338 j = 0;
339 }
340 ++j;
341 }
342
343 return 0;
344}
345*/
346