记录编号 |
40555 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[暑假培训2012] 单词缩写 |
最终得分 |
100 |
用户昵称 |
Makazeu |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.006 s |
提交时间 |
2012-07-18 12:08:59 |
内存使用 |
0.31 MiB |
显示代码纯文本
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <string>
- #include <algorithm>
- using namespace std;
- string ans,word,str,del[3]={"for","and","the"};
- int N,L,len;
- int main()
- {
- freopen("abbreviation.in","r",stdin);
- freopen("abbreviation.out","w",stdout);
- //freopen("in","r",stdin);
- //freopen("out","w",stdout);
- std::ios::sync_with_stdio(false);
- cin>>N; getline(cin,str);
- scanf("%d\n",&N);
- char c;
- while(N--)
- {
- getline(cin,str);
- //printf("%d\n",str.length());
- L=str.length();
- if(isalpha(str[L-1])==0 && str[L-1]!=' ')
- str=str.substr(0,L-1);
- str.push_back(' ');
- L=str.length();
- transform(str.begin(),str.end(),str.begin(),::tolower);
- //cout<<str<<endl;
- word.clear();
- ans.clear();
- for(int i=0;i<L;i++)
- {
- c=str[i];
- if(c!=' ')
- {
- word.push_back(c);
- continue;
- }
- len=word.length();
- if(len<3) {word.clear(); continue;}
- if(word==del[0] || word==del[1] || word==del[2])
- {word.clear(); continue;}
- ans.push_back(word[0]);
- word.clear();
- }
- // if(ans.length()==0) continue;
- transform(ans.begin(),ans.end(),ans.begin(),::toupper);
- cout<<ans<<'\r';
- }
- return 0;
- }