fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5. #define MAX_WORD_LEN 128
  6. #define MAX_ABBR_LEN 128
  7.  
  8. // 判斷這個單字是否需要略過
  9. int is_skip_word(const char *word) {
  10. return strcmp(word, "of") == 0 ||
  11. strcmp(word, "and") == 0 ||
  12. strcmp(word, "the") == 0 ||
  13. strcmp(word, "at") == 0;
  14. }
  15.  
  16. int main() {
  17. char word[MAX_WORD_LEN];
  18. char abbrs[1000][MAX_ABBR_LEN]; // 存所有縮寫,最多 1000 組
  19. int abbr_count = 0;
  20. char current_abbr[MAX_ABBR_LEN];
  21. int current_len = 0;
  22.  
  23. // 不斷從輸入中讀單字
  24. while (scanf("%s", word) != EOF) {
  25. int len = strlen(word);
  26. int is_last_word = 0;
  27.  
  28. // 如果最後一個字元是句號
  29. if (word[len - 1] == '.') {
  30. is_last_word = 1;
  31. word[len - 1] = '\0'; // 去掉句號方便處理
  32. }
  33.  
  34. if (!is_skip_word(word)) {
  35. current_abbr[current_len++] = toupper(word[0]);
  36. }
  37.  
  38. if (is_last_word) {
  39. current_abbr[current_len] = '\0'; // 結束縮寫字串
  40. strcpy(abbrs[abbr_count++], current_abbr); // 存到縮寫列表
  41. current_len = 0; // 重設下一組縮寫
  42. }
  43. }
  44.  
  45. // 輸出所有縮寫,用空白隔開
  46. for (int i = 0; i < abbr_count; ++i) {
  47. if (i > 0) printf(" ");
  48. printf("%s", abbrs[i]);
  49. }
  50. printf("\n");
  51.  
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0s 5288KB
stdin
the civil works administration. file transfer protocol. chief executive
officer. no problem. the social security administration. ante meridiem.
gross national product. close quarters combat. the agricultural adjustment
act. dynamic host configuration protocol. the civilian conservation corps.
united states geological survey. crime scene investigation.
stdout
CWA FTP CEO NP SSA AM GNP CQC AAA DHCP CCC USGS CSI