今天在做整理六級試題的時候,發現選項的排版不整齊不美觀。 例如: 61. A) up B) down C) in D) off 62. A) dwell B) rely C) press D) urge 63. A) execution B) distinction C) breakthrough D) process 64. A) paralyzed B) uneducated C) invisible D) sightless 65. A) scans B) enlarges C) sketches D) projects 66. A) behavior B) expression C) movement D) voice 67. A) on B) at C) in D) from 68. A) visual B) printed C) virtual D) spoken 69. A) stride B) trail C) haul D) footprint 70. A) Likewise B) Moreover C) However D) Though 71. A) but B) than C) or D) then 72. A) on B) for C) through D) to 73. A) estimates B) considers C) counts D) determines 74. A) settle B) own C) invest D) retain 75. A) schools B) children C) families D) companies 76. A) models B) modes C) cases D) collections 77. A) producing B) researching C) ascertaining D) assisting 78. A) true B) valuable C) authentic D) pleasant 79. A) after B) when C) before D) as 80. A) occasion B) moment C) sense D) event 看起來長短不一,也不對齊。所以我就想把它排好,整理成統一間距。 例如: 61. A) up B) down C) in D) off 62. A) dwell B) rely C) press D) urge 但是選項有很多啊,一題一題的改實在費事,所以編寫了一個程序來處理排版。 使用c語言: [cpp] #include <cstdio> char line[200]; int psn[4], stdpsn[] = {5, 25, 45, 65}; void swap(char &x, char &y) { char t; t = x; x = y; y = t; } void revise(char * a, int p) { int i; char t; p = p-1; for(i = p, t = ' '; t; i++) { swap(a[i], t); } a[i] = t; } int main(){ freopen("text.txt", "r", stdin); freopen("out.txt", "w", stdout); int p; while(gets(line)) { int t = 0; for(p = 0; line[p] != '\0'; p++) { if(line[p] == ')') psn[t++] = p; } // printf("%d %d %d %d\n", psn[0], psn[1], psn[2], psn[3]); for(int i = 1; i < 4; i++) { while(psn[i] < stdpsn[i]) { revise(line, psn[i]); for(int j = i; j < 4; j++) { psn[j]++; } } } puts(line); } return 0; } 只要把指定格式的原文本復制到txt文件中,運行程序,這樣可以迅速生成如下的格式: 61. A) up B) down C) in D) off 62. A) dwell B) rely C) press D) urge 63. A) execution B) distinction C) breakthrough D) process 64. A) paralyzed B) uneducated C) invisible D) sightless 65. A) scans B) enlarges C) sketches D) projects 66. A) behavior B) expression C) movement D) voice 67. A) on B) at C) in D) from 68. A) visual B) printed C) virtual D) spoken 69. A) stride B) trail C) haul D) footprint 70. A) Likewise B) Moreover C) However D) Though 71. A) but B) than C) or D) then 72. A) on B) for C) through D) to 73. A) estimates B) considers C) counts D) determines 74. A) settle B) own C) invest D) retain 75. A) schools B) children C) families D) companies 76. A) models B) modes C) cases D) collections 77. A) producing B) researching C) ascertaining D) assisting 78. A) true B) valuable C) authentic D) pleasant 79. A) after B) when C) before D) as 80. A) occasion B) moment C) sense D) event 個人覺得還是比較方便。 算法的分析: 首先確定每個反括號“)”在字符數組中的位置,記錄下來,然後不斷往其位置前添加空格“ ”,和標准格式的縮進進行對比,直到符合標准格式為止。很簡單的思路哦~