• 1164 Good in C


    When your interviewer asks you to write "Hello World" using C, can you do as the following figure shows?

    Input Specification:

    Each input file contains one test case. For each case, the first part gives the 26 capital English letters A-Z, each in a 7×5 matrix of C's and .'s. Then a sentence is given in a line, ended by a return. The sentence is formed by several words (no more than 10 continuous capital English letters each), and the words are separated by any characters other than capital English letters.

    It is guaranteed that there is at least one word given.

    Output Specification:

    For each word, print the matrix form of each of its letters in a line, and the letters must be separated by exactly one column of space. There must be no extra space at the beginning or the end of the word.

    Between two adjacent words, there must be a single empty line to separate them. There must be no extra line at the beginning or the end of the output.

    Sample Input:

    1. ..C..
    2. .C.C.
    3. C...C
    4. CCCCC
    5. C...C
    6. C...C
    7. C...C
    8. CCCC.
    9. C...C
    10. C...C
    11. CCCC.
    12. C...C
    13. C...C
    14. CCCC.
    15. .CCC.
    16. C...C
    17. C....
    18. C....
    19. C....
    20. C...C
    21. .CCC.
    22. CCCC.
    23. C...C
    24. C...C
    25. C...C
    26. C...C
    27. C...C
    28. CCCC.
    29. CCCCC
    30. C....
    31. C....
    32. CCCC.
    33. C....
    34. C....
    35. CCCCC
    36. CCCCC
    37. C....
    38. C....
    39. CCCC.
    40. C....
    41. C....
    42. C....
    43. CCCC.
    44. C...C
    45. C....
    46. C.CCC
    47. C...C
    48. C...C
    49. CCCC.
    50. C...C
    51. C...C
    52. C...C
    53. CCCCC
    54. C...C
    55. C...C
    56. C...C
    57. CCCCC
    58. ..C..
    59. ..C..
    60. ..C..
    61. ..C..
    62. ..C..
    63. CCCCC
    64. CCCCC
    65. ....C
    66. ....C
    67. ....C
    68. ....C
    69. C...C
    70. .CCC.
    71. C...C
    72. C..C.
    73. C.C..
    74. CC...
    75. C.C..
    76. C..C.
    77. C...C
    78. C....
    79. C....
    80. C....
    81. C....
    82. C....
    83. C....
    84. CCCCC
    85. C...C
    86. C...C
    87. CC.CC
    88. C.C.C
    89. C...C
    90. C...C
    91. C...C
    92. C...C
    93. C...C
    94. CC..C
    95. C.C.C
    96. C..CC
    97. C...C
    98. C...C
    99. .CCC.
    100. C...C
    101. C...C
    102. C...C
    103. C...C
    104. C...C
    105. .CCC.
    106. CCCC.
    107. C...C
    108. C...C
    109. CCCC.
    110. C....
    111. C....
    112. C....
    113. .CCC.
    114. C...C
    115. C...C
    116. C...C
    117. C.C.C
    118. C..CC
    119. .CCC.
    120. CCCC.
    121. C...C
    122. CCCC.
    123. CC...
    124. C.C..
    125. C..C.
    126. C...C
    127. .CCC.
    128. C...C
    129. C....
    130. .CCC.
    131. ....C
    132. C...C
    133. .CCC.
    134. CCCCC
    135. ..C..
    136. ..C..
    137. ..C..
    138. ..C..
    139. ..C..
    140. ..C..
    141. C...C
    142. C...C
    143. C...C
    144. C...C
    145. C...C
    146. C...C
    147. .CCC.
    148. C...C
    149. C...C
    150. C...C
    151. C...C
    152. C...C
    153. .C.C.
    154. ..C..
    155. C...C
    156. C...C
    157. C...C
    158. C.C.C
    159. CC.CC
    160. C...C
    161. C...C
    162. C...C
    163. C...C
    164. .C.C.
    165. ..C..
    166. .C.C.
    167. C...C
    168. C...C
    169. C...C
    170. C...C
    171. .C.C.
    172. ..C..
    173. ..C..
    174. ..C..
    175. ..C..
    176. CCCCC
    177. ....C
    178. ...C.
    179. ..C..
    180. .C...
    181. C....
    182. CCCCC
    183. HELLO~WORLD!

    Sample Output:

    1. C...C CCCCC C.... C.... .CCC.
    2. C...C C.... C.... C.... C...C
    3. C...C C.... C.... C.... C...C
    4. CCCCC CCCC. C.... C.... C...C
    5. C...C C.... C.... C.... C...C
    6. C...C C.... C.... C.... C...C
    7. C...C CCCCC CCCCC CCCCC .CCC.
    8. C...C .CCC. CCCC. C.... CCCC.
    9. C...C C...C C...C C.... C...C
    10. C...C C...C CCCC. C.... C...C
    11. C.C.C C...C CC... C.... C...C
    12. CC.CC C...C C.C.. C.... C...C
    13. C...C C...C C..C. C.... C...C
    14. C...C .CCC. C...C CCCCC CCCC.

     题意:

    对每个单词,将其每个字母用矩阵形式在一行中输出,字母间有一列空格分隔。单词的首尾不得有多余空格。

    相邻的两个单词间必须有一空行分隔。输出的首尾不得有多余空行。

    图解:

     

     AC代码:(已注释)

    1. /*
    2. * @Author: Spare Lin
    3. * @Project: AcWing2022
    4. * @Date: 2022/6/29 11:12
    5. * @Description: AcWing 4276. 擅长C 来源:PAT甲级真题1164
    6. */
    7. #include <iostream>
    8. using namespace std;
    9. char g[26][7][6]; //输入单词 26个7*5的矩阵
    10. bool is_first = true;//判断是否是第一行
    11. void output(string word) { //输出每个单词
    12. if (word.empty()) return; //单词为空 不需要输出
    13. if(is_first) is_first = false; //如果是第一个单词则不输出换行 否则输出换行
    14. else cout << '\n';
    15. char str[7][60] = {0};
    16. for (int i = 0; i < word.size(); ++i) {
    17. //打印单词每个字母的 7*5矩阵
    18. for (int j = 0; j < 7; ++j) {
    19. for (int k = 0; k < 5; ++k) {
    20. //矩阵的行放在第j行 列应该为i * 6 + k
    21. str[j][i * 6 + k] = g[word[i] - 'A'][j][k];
    22. }
    23. }
    24. }
    25. //从第二个矩阵开始填充' '在每个矩阵的起始列前一个位置 即 i * 6 - 1
    26. for (int i = 1; i < word.size(); ++i) {
    27. for (int j = 0; j < 7; ++j) {
    28. str[j][i * 6 - 1] = ' ';
    29. }
    30. }
    31. for (int i = 0; i < 7; ++i) {
    32. cout << str[i] << '\n';
    33. }
    34. }
    35. int main() {
    36. for (int i = 0; i < 26; ++i) {
    37. for (int j = 0; j < 7; ++j) {
    38. cin >> g[i][j];
    39. }
    40. }
    41. cin.get(); //吸收换行
    42. string word, str;
    43. getline(cin, word);
    44. for (auto &x: word) {
    45. if (isupper(x)) {
    46. str += x;
    47. } else {
    48. output(str);
    49. str.clear();
    50. }
    51. }
    52. output(str); //最后可能还剩下一个单词
    53. return 0;
    54. }

  • 相关阅读:
    Janus之自问自答
    自动化测试及Selenium
    UsernamePasswordAuthenticationFilter执行流程
    JavaScript严格模式
    Linux入门之关机、挂起和休眠
    浅谈测试小白到测试大牛的成长历程(分四个境界)
    常用的网络攻击手段
    达梦数据库 视图 错误 [22003]: 数据溢出
    如何在填报场景中使用数据绑定获取数据源
    算法竞赛入门【码蹄集进阶塔335题】(MT2281-2285)
  • 原文地址:https://blog.csdn.net/weixin_55664293/article/details/125548383