第一次用C++ stl写题 不知道怎么读入空格。。。
查看原帖
第一次用C++ stl写题 不知道怎么读入空格。。。
1114927
Lolaandd楼主2023/11/26 19:07
#include<cstdio>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
int main (){
	int cnt=0;
	map <string,int> list;
	map <string,int> firstplace;
	string word;
	cin >> word;
	for (int i=0;i<word.length();i++){
		word[i]=tolower(word[i]);
	}
	string temp;
	while (cin >> temp) 
	{
		for(int i=0;i<temp.length();i++)
		{
			temp[i]=tolower(temp[i]);
		}//标准化
		if(!list[temp]) {
		 list[temp]=0;
		 firstplace[temp]=cnt;
		}
		cnt++; 
		list[temp]+=1;
		temp="";
	}
	if(!list[word]) printf("-1");
	else{
		printf("%d %d",list[word],firstplace[word]);
	}
	return 0;
}````
2023/11/26 19:07
加载中...