1 条题解
-
0
C++ :
#include <iostream> #include <string.h> #include <stdio.h> #include <cstdlib> using namespace std; const int WORD_LEN = 21; const int MAX_LEN = 1000011; int main() { static char key[WORD_LEN], article[MAX_LEN]; int counter = 0, location, keylen; gets(key); gets(article); for(keylen = 0; isalpha(key[keylen]); keylen++); for(int i = 0; article[i]; ++i) { if (!isalpha(article[i])) { continue; } else if((strncasecmp(&article[i], key, keylen)==0) && (!isalpha(article[i + keylen]))) { if(counter == 0) { location = i; } counter++; i += keylen; } else { while (isalpha(article[i])) { i++; } } } if(counter != 0) { cout << counter << ' ' << location << endl; } else { cout << -1 << endl; } return 0; }
Pascal :
var temp,str:string; times,cur,pos,s:longint; ch:char; begin readln(str);times:=0;cur:=-2; while not eoln do begin temp:=''; while not eoln do begin read(ch);inc(cur); if length(temp)=1 then s:=cur; if ch<>' ' then begin temp:=temp+ch; continue; end; break; end; if upcase(temp)=upcase(str) then inc(times); if (times=1) and (upcase(temp)=upcase(str)) then pos:=s; end; if times>0 then write(times,' ',pos); if times=0 then write('-1'); end.
- 1
信息
- ID
- 575
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者