20分AC on #2 and #4
查看原帖
20分AC on #2 and #4
747917
ygwlan楼主2023/9/29 19:33

贴代码

#include <bits/stdc++.h>
#include <cstdio>// 缺省源弄的 
using namespace std;
string tosmall(string s){//单词变小写化 
	int len=s.size();
	for(int i=0;i<len;i++){
		if(s[i]>='A'&&s[i]<='Z')
		s[i]=s[i]-'A'+'a';
	}
	return s;
}
int main(){
//	freopen("stat.in","r",stdin);
//	freopen("stat.out","w",stdout);
	string aim;
	string l;
	cin>>aim;
	aim=tosmall(aim);//变小 
	bool f=0;//有木有单词 
	int i=0; //当前单词开头的坐标 
	int sum=0,first=0;//单词数和第一个的坐标 
	while(cin>>l){
		l=tosmall(l);//变小 
		if(l==aim){ //一样 
			sum++;
			if(!f){//假如以前没有出现过(第一次出现aim) 
				f=1;//出现了 
				first=i;//第一次的坐标 
			}
		}
		i+=l.size();//更新下个单词开头 
	}
	if(f){//if have 
		cout<<sum<<" "<<first;
	}
	else//else
	cout<<-1;
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}

2023/9/29 19:33
加载中...