NOIP2011T2 统计单词数

 

#include<iostream>
#include<cstdio>
#include<cctype>
#include<string>
#include<algorithm>
using namespace std;
string s,t;
int p=-1,x=0,b;
int main(){
    getline(cin,s);
    for(int i=0;i<s.size();i++)s[i]=tolower(s[i]);s=" "+s+" ";
    getline(cin,t);
    for(int i=0;i<t.size();i++)t[i]=tolower(t[i]);t=" "+t+" ";
    while(1){
    	p=t.find(s,p+1);
    	if(p==-1)break;
    	if(!x)b=p;
    	x++;
    }
    if(!x)puts("-1");
    else printf("%d %d\n",x,b);
    return 0;
}

  

 

 

var
    s:ansistring;
    r,ss:string;
    lr,ls,i,num,p:longint;
begin
    assign(input,'stat.in'); reset(input);
    assign(output,'stat.out'); rewrite(output);
    readln(r); readln(s);
    r:=' '+r+' '; s:=' '+s+' ';
    lr:=length(r); ls:=length(s);
    for i:=1 to lr do
        if r[i]>='a' then r[i]:=chr(ord(r[i])-32);
    for i:=1 to ls do
        if s[i]>='a' then s[i]:=chr(ord(s[i])-32);
    for i:=ls-lr+1 downto 1 do
        if r=copy(s,i,lr) then begin inc(num); p:=i; end;
    if num=0 then writeln(-1) else  writeln(num,' ',p-1);
    close(input); close(output);
end.

 

本题若用upcase()函数,则显示“编译失败”

posted @ 2013-10-24 14:06  qilinart  阅读(395)  评论(0)    收藏  举报