比赛 防止颓废的小练习v0.15 评测结果 AAAAAAAAAA
题目名称 统计单词数 最终得分 100
用户昵称 Rapiz 运行时间 0.035 s
代码语言 C++ 内存使用 6.97 MiB
提交时间 2016-10-17 20:51:34
显示代码纯文本
  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cctype>
  4. #define file(x) "stat."#x
  5. const int LEN=1e6+10;
  6. char a[LEN],b[LEN],buf[LEN];
  7. int l1,l2,nxt[LEN],pos,cnt,tol,ans;
  8. bool match(){
  9. if(l1!=l2) return false;
  10. for(int i=1;i<=l2;i++) if(a[i]!=tolower(b[i])) return false;
  11. return true;
  12. }
  13. bool read(){
  14. l2=0;
  15. pos++;
  16. while(buf[pos]&&isspace(buf[pos])) pos++;
  17. b[++l2]=buf[pos];
  18. while(isgraph(buf[pos+1])) b[++l2]=buf[++pos];
  19. return pos<=tol;
  20. }
  21. int main(){
  22. freopen(file(in),"r",stdin);
  23. freopen(file(out),"w",stdout);
  24. gets(a+1);
  25. gets(buf+1);
  26. l1=strlen(a+1);
  27. tol=strlen(buf+1);
  28. for(int i=1;i<=l1;i++) a[i]=tolower(a[i]);
  29. while(read()) {
  30. if(match()){
  31. if(!cnt) ans=pos-l2;
  32. cnt++;
  33. }
  34. }
  35. if(cnt) printf("%d %d",cnt,ans);
  36. else printf("-1");
  37. }