比赛 防止颓废的小练习v0.15 评测结果 AAWAWWWWWW
题目名称 统计单词数 最终得分 30
用户昵称 WHZ0325 运行时间 0.286 s
代码语言 C++ 内存使用 0.31 MiB
提交时间 2016-10-17 21:00:02
显示代码纯文本
  1. #include <fstream>
  2. #include <string>
  3. #include <cctype>
  4. #include <vector>
  5. using namespace std;
  6. ifstream fin("stat.in");
  7. ofstream fout("stat.out");
  8. inline void s_tolower(string &s) {
  9. for(unsigned int i=0;i<s.length();i++) {
  10. s[i]=tolower(s[i]);
  11. }
  12. }
  13. string s;
  14. vector<string> v;
  15. int main() {
  16. fin>>s;
  17. s_tolower(s);
  18. bool first=true;
  19. int out=0;
  20. int first_out;
  21. string get_s;
  22. getline(fin,get_s,char(EOF));
  23. int last=1;
  24. for(unsigned int i=1;i<get_s.length();i++) {
  25. if((i==get_s.length()-1)||(get_s[i]==' '&&get_s[i+1]!=' ')) {
  26. v.push_back(get_s.substr(last,i-last));
  27. if(v.back()[v.back().length()-1]==' ') {
  28. v.push_back(v.back());
  29. }
  30. last=i+1;
  31. }
  32. }
  33. for(unsigned int i=0;i<v.size();i++) {
  34. s_tolower(v[i]);
  35. if(s==v[i]) {
  36. if(first) {
  37. first_out=i;
  38. first=false;
  39. }
  40. out++;
  41. }
  42. }
  43. if(out==0) {
  44. fout<<"-1"<<endl;
  45. }
  46. else {
  47. fout<<out<<" "<<first_out<<endl;
  48. }
  49. fin.close();
  50. fout.close();
  51. return 0;
  52. }