复健计划第一题
大小写字母(a与A)编号相差32
string输入用getline
输出用puts
#include<iostream> #include<cstdio> #include<cstring> using namespace std; string a,b; int la,lb; void chk(int i){ if('a'<=b[i]&&b[i]<='z') b[i]-=32; } void solve(){ int fi=-1,t=0; chk(0); for(int i=0,j;i<lb;chk(++i)){ for(j=0;j<la;++j,chk(++i)) if(i==lb||a[j]!=b[i]) break; // printf("%d -- %d :",i,j); // cout<<a[i]<<endl; if(j==la&&b[i]==' '){ // printf("ok\n"); if(fi==-1) fi=i-la; ++t; }else while(b[i]!=' '&&i<lb) ++i; } if(t!=0) printf("%d %d",t,fi); else printf("-1"); } int main(){ // freopen("P1308_1.in","r",stdin); getline(cin,a); la=a.size(); getline(cin,b); lb=b.size(); // cout<<a<<endl<<b<<endl; for(int i=0;i<la;++i) if('a'<=a[i]&&a[i]<='z') a[i]-=32; solve(); return 0; }