记录编号 40555 评测结果 AAAAAAAAAA
题目名称 [暑假培训2012] 单词缩写 最终得分 100
用户昵称 GravatarMakazeu 是否通过 通过
代码语言 C++ 运行时间 0.006 s
提交时间 2012-07-18 12:08:59 内存使用 0.31 MiB
显示代码纯文本
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <string>
  6. #include <algorithm>
  7. using namespace std;
  8. string ans,word,str,del[3]={"for","and","the"};
  9. int N,L,len;
  10. int main()
  11. {
  12. freopen("abbreviation.in","r",stdin);
  13. freopen("abbreviation.out","w",stdout);
  14. //freopen("in","r",stdin);
  15. //freopen("out","w",stdout);
  16. std::ios::sync_with_stdio(false);
  17. cin>>N; getline(cin,str);
  18. scanf("%d\n",&N);
  19. char c;
  20. while(N--)
  21. {
  22. getline(cin,str);
  23. //printf("%d\n",str.length());
  24. L=str.length();
  25. if(isalpha(str[L-1])==0 && str[L-1]!=' ')
  26. str=str.substr(0,L-1);
  27. str.push_back(' ');
  28. L=str.length();
  29. transform(str.begin(),str.end(),str.begin(),::tolower);
  30. //cout<<str<<endl;
  31. word.clear();
  32. ans.clear();
  33. for(int i=0;i<L;i++)
  34. {
  35. c=str[i];
  36. if(c!=' ')
  37. {
  38. word.push_back(c);
  39. continue;
  40. }
  41. len=word.length();
  42. if(len<3) {word.clear(); continue;}
  43. if(word==del[0] || word==del[1] || word==del[2])
  44. {word.clear(); continue;}
  45. ans.push_back(word[0]);
  46. word.clear();
  47. }
  48. // if(ans.length()==0) continue;
  49. transform(ans.begin(),ans.end(),ans.begin(),::toupper);
  50. cout<<ans<<'\r';
  51. }
  52. return 0;
  53. }