UVA 400 (13.08.05)

本文介绍了一个模拟 Unix 系统中 ls 命令功能的程序设计与实现。该程序能够读取文件名列表,对其进行排序,并按照特定格式输出到多个列中。输出格式取决于最长文件名的长度,每行不超过60个字符。
 Unix ls 

The computer company you work for is introducing a brand new computer line and is developing a new Unix-like operating system to be introduced along with the new computer. Your assignment is to write the formatter for the ls function.

 

Your program will eventually read input from a pipe (although for now your program will read from the input file). Input to your program will consist of a list of (F) filenames that you will sort (ascending based on the ASCII character values) and format into (C) columns based on the length (L) of the longest filename. Filenames will be between 1 and 60 (inclusive) characters in length and will be formatted into left-justified columns. The rightmost column will be the width of the longest filename and all other columns will be the width of the longest filename plus 2. There will be as many columns as will fit in 60 characters. Your program should use as few rows (R) as possible with rows being filled to capacity from left to right.

 

Input

The input file will contain an indefinite number of lists of filenames. Each list will begin with a line containing a single integer( tex2html_wrap_inline41 ).There will then be N lines each containing one left-justifiedfilename and the entire line's contents (between 1 and 60 characters) are considered to be part of the filename. Allowable characters are alphanumeric (a to z, A to Z, and 0 to 9) and from the followingset { ._- } (not including the curly braces). There will be no illegalcharacters in any of the filenames and no line will be completely empty.

Immediately following the last filename will be the N for the next set or the end of file. You should read and format all sets in the input file.

 

Output

For each set of filenames you should print a line of exactly 60 dashes (-) followed by the formatted columns of filenames. The sorted filenames 1 to R will be listed down column 1; filenames R+1 to 2R listed down column 2; etc.

 

Sample Input

 

10
tiny
2short4me
very_long_file_name
shorter
size-1
size2
size3
much_longer_name
12345678.123
mid_size_name
12
Weaser
Alfalfa
Stimey
Buckwheat
Porky
Joe
Darla
Cotton
Butch
Froggy
Mrs_Crabapple
P.D.
19
Mr._French
Jody
Buffy
Sissy
Keith
Danny
Lori
Chris
Shirley
Marsha
Jan
Cindy
Carol
Mike
Greg
Peter
Bobby
Alice
Ruben

 

Sample Output

 

------------------------------------------------------------
12345678.123         size-1               
2short4me            size2                
mid_size_name        size3                
much_longer_name     tiny                 
shorter              very_long_file_name  
------------------------------------------------------------
Alfalfa        Cotton         Joe            Porky          
Buckwheat      Darla          Mrs_Crabapple  Stimey         
Butch          Froggy         P.D.           Weaser         
------------------------------------------------------------
Alice       Chris       Jan         Marsha      Ruben       
Bobby       Cindy       Jody        Mike        Shirley     
Buffy       Danny       Keith       Mr._French  Sissy       
Carol       Greg        Lori        Peter


题意:

制表输出给出的一堆单词;


制表规则:

根据所有单词中, 长度最长的一个, 决定了有几列

一行最多输出60个字符


做法及注意点:

网上挺多份代码说60会WA, 所以我听信了, 根据别人题解的建议, 用62;

然后输出的话我们可以先qsort一下, 接着, 看我AC代码吧, 怎么按列输出


AC代码:

 

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

char str[100][65];

int cmp(const void *a, const void *b) {
	return strcmp((char *)a, (char *)b);
} 

int main() {
	int N;
	int row, col;
	while(scanf("%d", &N) != EOF) {
		getchar();
		int max_l = 0;
		for(int i = 0; i < N; i++) {
			gets(str[i]);
			if(strlen(str[i]) > max_l)
				max_l = strlen(str[i]);
		}
		qsort(str, N, sizeof(str[0]), cmp);
		printf("------------------------------------------------------------\n");
		col = 62 / (max_l+2);
		row = (N-1) / col+1;
		for(int i = 0 ; i < row; i++) {
			for(int j = 0; j < col; j++) {
				int pos = j * row + i;
				int len, blank;
				if(pos >= N)
					break;
				printf("%s", str[pos]);
				len = strlen(str[pos]);
				blank = max_l - len;
				for(int k = 0; k < blank; k++)
					printf(" ");
				printf("  ");
			}
			printf("\n");
		}
	}
	return 0;
}

 

Temp. Rmax Rnor Rmin (deg. C) (k Ohms) (k Ohms) (k Ohms) -30 10107.5781 9528.169 98973.8916 -29 9476.8418 8939.291 8424.6436 -28 8889.5684 8390.6416 7912.5898 -27 8342.4883 7879.2207 7434.981 -26 7832.6064 7402.2734 6989.2876 -25 7357.1626 6957.2637 6573.1797 -24 6913.6216 6541.8574 6184.5132 -23 6499.6475 6153.9048 5821.3096 -22 6113.0889 5791.4233 5481.7456 -21 5751.9639 5452.5874 5164.1401 -20 5414.4468 5135.7109 4866.9399 -19 5098.8525 4839.2397 4588.7119 -18 4803.6255 4561.7378 4328.1313 -17 4527.3296 4301.8774 4083.9729 -16 4268.6387 4058.4324 3855.1047 -15 4026.3279 3830.2695 3640.4785 -14 3799.2622 3616.3381 3439.1235 -13 3586.3933 3415.668 3250.1421 -12 3386.751 3227.3589 3072.7004 -11 3199.436 3050.5776 2906.0273 -10 3023.616 2884.5518 2749.4067 -9 2858.5188 2728.5645 2602.1738 -8 2703.4292 2581.9509 2463.7119 -7 2557.6826 2444.0942 2333.4482 -6 2420.6628 2314.4211 2210.8508 -5 2291.7983 2192.3994 2095.4241 -4 2170.5571 2077.5344 1986.7085 -3 2056.4448 1969.3652 1884.2756 -2 1949.0024 1867.4645 1787.7272 -1 1847.8026 1771.4333 1696.692 0 1752.4481 1680.9012 1610.8245 1 1662.5682 1595.5225 1529.8024 2 1577.8188 1514.9752 1453.3256 3 1497.8783 1438.9592 1381.1138 4 1422.4474 1367.1947 1312.9055 5 1351.2471 1299.4207 1248.4574 6 1284.0171 1187.541 -0.8 7 1220.5142 1174.885 -0.8 8 1160.5117 1117.6835 1075.4669 9 1103.7977 1063.59 1023.9245 10 1050.1742 1012.4188 975.1424 11 999.4562 963.9966 928.9582 12 951.4709 918.1609 885.2197 13 906.0564 874.7598 843.7841 14 863.0613 833.651 804.5182 15 822.344 794.7014 767.2968 16 783.7717 757.786 732.0025 17 747.2203 722.7881 698.5256 18 712.5732 689.598 666.763 19 679.7214 658.1129 636.6179 20 648.5624 628.2363 607.9995 21 619.0003 599.8777 580.8226 22 590.9451 572.9522 555.0073 23 564.312 547.3799 530.478 24 539.0218 523.086 507.1644 25 515 500 485 26 492.6184 478.0557 463.5059 27 471.3282 457.1908 443.0783 28 451.0707 437.3468 423.6588 29 431.7906 418.4686 405.1926 30 413.4358 400.5044 387.6282 31 395.9573 383.4052 370.9169 32 379.3089 367.1253 355.0132 33 363.4471 351.6212 339.8739 34 348.3307 336.8521 325.4585 35 333.9211 322.7796 311.7289 36 320.1818 309.3673 298.6491 37 307.0782 296.5811 286.1851 38 294.5779 284.3887 274.3049 39 282.6502 272.7596 262.9783 40 271.2659 261.6651 252.1769 41 260.3979 251.078 241.8738 42 250.0201 240.9726 232.0435 43 240.1081 231.3248 222.6621 44 230.6387 222.1115 213.707 45 221.5902 213.3112 205.1568 46 212.9417 204.9034 196.9911 47 204.6736 196.8687 189.191 48 196.7676 189.1889 181.7383 49 189.2059 181.8464 174.6159 50 181.972 174.8251 167.8076 51 175.0502 168.1092 161.2982 52 168.4254 161.6841 155.073 53 162.0837 155.5359 149.1183 54 156.0115 149.6513 143.4212 55 150.1962 144.0179 137.9693 56 144.6258 138.6236 132.751 57 139.2888 133.4574 127.755 58 134.1743 128.5084 122.9711 59 129.272 123.7667 118.3891 60 124.5723 119.2225 113.9997 61 120.0658 114.8667 109.7939 62 115.7436 110.6907 105.7631 63 111.5974 106.6862 101.8994 64 107.6193 102.8455 98.1949 65 103.8017 99.161 94.6426 66 100.1374 95.6258 91.2353 67 96.6196 92.2332 87.9666 68 93.2417 88.9766 84.8302 69 89.9976 85.8502 81.8202 70 86.8813 82.8481 78.9309 71 83.8874 79.9647 76.157 72 81.0103 77.195 73.4932 73 78.2452 74.534 70.9349 74 75.5871 71.9768 68.4773 75 73.0314 69.519 66.116 76 70.5737 67.1563 63.8469 77 68.2099 64.8847 61.666 78 65.936 62.7001 59.5694 79 63.7481 60.5989 57.5535 80 61.6426 58.5776 55.6149 81 59.6162 56.6328 53.7503 82 57.6654 54.7612 51.9565 83 55.7871 52.9598 50.2305 84 53.9784 51.2257 48.5696 85 52.2363 49.556 46.971 86 50.5582 47.9482 45.432 87 48.9413 46.3996 43.9502 88 47.3833 44.9078 42.5233 89 45.8817 43.4705 41.1489 90 44.4343 42.0855 39.825 91 43.0388 40.7507 38.5495 92 41.6933 39.464 37.3203 93 40.3956 38.2235 36.1357 94 39.1439 37.0274 34.9937 95 37.9365 35.8738 33.8928 96 36.7715 34.7612 32.8313 97 35.6472 33.6878 31.8075 98 34.5621 32.6522 30.8201 99 33.5147 31.6529 29.8675 100 32.5035 30.6883 28.9484 101 31.5271 29.7573 28.0615 102 30.5842 28.8584 27.2056 103 29.6735 27.9905 26.3793 104 28.7937 27.1524 25.5816 105 27.9437 26.3429 24.8114 106 27.1223 25.5609 24.0677 107 26.3286 24.8054 23.3493 108 25.5613 24.0753 22.6553 109 24.8197 23.3698 21.9849 110 24.1026 22.6879 21.3371 111 23.4092 22.0287 20.711 112 22.7386 21.3914 20.1059 113 22.09 20.7752 19.521 114 21.4626 20.1792 18.9555 115 20.8556 19.6028 18.4087 116 20.2682 19.0452 17.8799 117 19.6997 18.5057 17.3685 118 19.1495 17.9838 16.8737 119 18.617 17.4786 16.3951 120 18.1013 16.9897 15.932 121 17.6021 16.5164 15.4838 122 17.1186 16.0583 15.05 123 16.6504 15.6147 14.6302 124 16.1968 15.1851 14.2237 125 15.7574 14.769 13.8302 126 15.3317 14.366 13.4491 127 14.9192 13.9757 13.08 128 14.5194 13.5974 12.7225 129 14.132 13.231 12.3763 130 13.7564 12.8758 12.0408 131 13.3922 12.5316 11.7157 132 13.0392 12.1979 11.4007 133 12.6968 11.8745 11.0954 134 12.3648 11.5608 10.7994 135 12.0427 11.2567 10.5126 136 11.7303 10.9618 10.2344 137 11.4272 10.6758 9.9647 138 11.1332 10.3983 9.7032 139 10.8478 10.1291 9.4495 140 10.5709 9.8679 9.2034 141 10.3021 9.6145 8.9648 142 10.0411 9.3686 8.7332 143 9.7878 9.1299 8.5085 144 9.5419 8.8981 8.2904 145 9.303 8.6732 8.0787 146 9.0711 8.4548 7.8733 147 8.8458 8.2428 7.6739 148 8.627 8.0368 7.4803 149 8.4144 7.8368 7.2923 150 8.2079 7.6425 7.1097 151 8.0072 7.4538 6.9324 152 7.8122 7.2705 6.7602 153 7.6227 7.0923 6.5929 154 7.4384 6.9192 6.4304 155 7.2594 6.751 6.2725 156 7.0853 6.5874 6.1191 157 6.916 6.4285 5.97 158 6.7514 6.274 5.8251 159 6.5913 6.1238 5.6842 160 6.4357 5.9777 5.5473 161 6.2843 5.8356 5.4142 162 6.137 5.6975 5.2847 163 5.9937 5.5631 5.1589 164 5.8542 5.4324 5.0365 165 5.7186 5.3053 4.9174 166 5.5865 5.1816 4.8016 167 5.458 5.0612 4.689 168 5.333 4.9441 4.5794 169 5.2112 4.8301 4.4728 170 5.0927 4.7191 4.369 171 4.9773 4.6111 4.268 172 4.865 4.506 4.1698 173 4.7555 4.4036 4.0741 174 4.649 4.304 3.981 175 4.5452 4.2069 3.8903 176 4.4441 4.1124 3.8021 177 4.3456 4.0204 3.7161 178 4.2497 3.9307 3.6325 179 4.1562 3.8434 3.551 180 4.0651 3.7583 3.4716 181 3.9763 3.6754 3.3943 182 3.8898 3.5947 3.3189 183 3.8055 3.516 3.2455 184 3.7233 3.4393 3.174 185 3.6432 3.3645 3.1044 186 3.5651 3.2916 3.0365 187 3.4889 3.2206 2.9703 188 3.4146 3.1514 2.9058 189 3.3422 3.0839 2.8429 190 3.2716 3.018 2.7817 191 3.2027 2.9538 2.7219 192 3.1355 2.8912 2.6637 193 3.0699 2.8302 2.6069 194 3.0059 2.7706 2.5515 195 2.9435 2.7125 2.4974 196 2.8827 2.6559 2.4447 197 2.8232 2.6006 2.3933 198 2.7653 2.5466 2.3432 199 2.7087 2.494 2.2943 200 2.6534 2.4426 2.2466 201 2.5995 2.3925 2.2 202 2.5469 2.3436 2.1546 203 2.4955 2.2958 2.1102 204 2.4453 2.2492 2.0669 205 2.3963 2.2037 2.0247 206 2.3485 2.1592 1.9835 207 2.3017 2.1159 1.9432 208 2.2561 2.0735 1.9039 209 2.2115 2.0321 1.8656 210 2.168 1.9917 1.8281 211 2.1255 1.9522 1.7915 212 2.0839 1.9137 1.7558 213 2.0433 1.876 1.7209 214 2.0036 1.8392 1.6868 215 1.9649 1.8033 1.6535 216 1.927 1.7682 1.621 217 1.89 1.7339 1.5892 218 1.8538 1.7003 1.5582 219 1.8184 1.6676 1.5279 220 1.7838 1.6355 1.4982 221 1.75 1.6042 1.4693 222 1.717 1.5736 1.441 223 1.6846 1.5437 1.4133 224 1.653 1.5145 1.3863 225 1.6221 1.4859 1.3598 226 1.5919 1.4579 1.334 227 1.5624 1.4306 1.3087 228 1.5334 1.4038 1.284 229 1.5052 1.3777 1.2599 230 1.4775 1.3521 1.2362 231 1.4504 1.3271 1.2132 232 1.424 1.3026 1.1906 233 1.3981 1.2787 1.1685 234 1.3727 1.2553 1.1469 235 1.3479 1.2324 1.1257 236 1.3236 1.21 1.105 237 1.2999 1.188 1.0848 238 1.2766 1.1666 1.065 239 1.2539 1.1456 1.0457 240 1.2316 1.125 1.0267 241 1.2098 1.1049 1.0082 242 1.1884 1.0852 0.99 243 1.1675 1.0659 0.9722 244 1.1471 1.047 0.9549 245 1.127 1.0285 0.9378 246 1.1074 1.0105 0.9212 247 1.0882 0.9927 0.9049 248 1.0693 0.9754 0.8889 249 1.0509 0.9584 0.8733 250 1.0328 0.9418 0.858 251 1.0152 0.9255 0.843 252 0.9978 0.9095 0.8283 253 0.9808 0.8939 0.8139 254 0.9642 0.8786 0.7998 255 0.9479 0.8636 0.7861 256 0.9319 0.8489 0.7725 257 0.9163 0.8345 0.7593 258 0.901 0.8204 0.7463 259 0.8859 0.8066 0.7336 260 0.8712 0.793 0.7212 261 0.8568 0.7797 0.709 262 0.8426 0.7667 0.6971 263 0.8287 0.754 0.6854 264 0.8151 0.7415 0.6739 265 0.8018 0.7292 0.6626 266 0.7887 0.7172 0.6516 267 0.7759 0.7055 0.6408 268 0.7634 0.6939 0.6302 269 0.751 0.6826 0.6199 270 0.7389 0.6715 0.6097 271 0.7271 0.6606 0.5997 272 0.7155 0.65 0.5899 273 0.7041 0.6395 0.5803 274 0.6929 0.6292 0.5709 275 0.6819 0.6192 0.5617 276 0.6712 0.6093 0.5527 277 0.6606 0.5996 0.5438 278 0.6502 0.5901 0.5351 279 0.6401 0.5808 0.5266 280 0.6301 0.5717 0.5182 281 0.6203 0.5627 0.51 282 0.6107 0.5539 0.502 283 0.6013 0.5453 0.4941 284 0.5921 0.5368 0.4863 285 0.583 0.5285 0.4787 286 0.5741 0.5204 0.4712 287 0.5653 0.5123 0.4639 288 0.5567 0.5045 0.4567 289 0.5483 0.4968 0.4497 290 0.54 0.4892 0.4428 291 0.5319 0.4818 0.436 292 0.524 0.4745 0.4293 293 0.5161 0.4673 0.4228 294 0.5084 0.4603 0.4163 295 0.5009 0.4534 0.41 296 0.4935 0.4466 0.4039 297 0.4862 0.44 0.3978 298 0.4791 0.4334 0.3918 299 0.472 0.427 0.386 300 0.4651 0.4207 0.3802 301 0.4584 0.4145 0.3746 302 0.4517 0.4085 0.369 303 0.4452 0.4025 0.3636 304 0.4388 0.3966 0.3582 305 0.4324 0.3909 0.353 306 0.4262 0.3852 0.3478 307 0.4202 0.3796 0.3427 308 0.4142 0.3742 0.3378 309 0.4083 0.3688 0.3329 310 0.4025 0.3635 0.3281 311 0.3968 0.3584 0.3233 312 0.3913 0.3533 0.3187 313 0.3858 0.3483 0.3141 314 0.3804 0.3434 0.3097 315 0.3751 0.3385 0.3053 316 0.3699 0.3338 0.3009 317 0.3648 0.3291 0.2967 318 0.3597 0.3245 0.2925 319 0.3548 0.32 0.2884 320 0.3499 0.3156 0.2844 321 0.3451 0.3112 0.2804 322 0.3404 0.3069 0.2765 323 0.3358 0.3027 0.2727 324 0.3313 0.2986 0.2689 325 0.3268 0.2945 0.2652 326 0.3224 0.2905 0.2616 327 0.3181 0.2866 0.258 328 0.3138 0.2827 0.2545 329 0.3096 0.2789 0.251 330 0.3055 0.2752 0.2476 331 0.3015 0.2715 0.2443 332 0.2975 0.2679 0.241 333 0.2936 0.2643 0.2378 334 0.2897 0.2608 0.2346 335 0.2859 0.2574 0.2314 336 0.2822 0.254 0.2284 337 0.2785 0.2506 0.2253 338 0.2749 0.2474 0.2224 339 0.2714 0.2441 0.2194 340 0.2679 0.241 0.2166 341 0.2645 0.2378 0.2137 342 0.2611 0.2348 0.2109 343 0.2577 0.2317 0.2082 344 0.2545 0.2288 0.2055 345 0.2512 0.2258 0.2028 346 0.2481 0.223 0.2002 347 0.2449 0.2201 0.1976 348 0.2419 0.2173 0.1951 349 0.2388 0.2146 0.1926 350 0.2359 0.2119 0.1902 根据以上数据求出精确的Steinhart-Hart方程
08-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值