tijie
2025-07-15 11:23:08
发布于:广东
4阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int main(){
int cnt = 0,place = 0;
string word,tmp;
cin >> word;
for(int i = 0;i < word.length();i++){ //降为小写
if(word[i] < 'a'){
word[i] += 32;
}
}
while(cin >> tmp){ //一个词一个词地输入句子
int yes = 0;
bool first = false;
for(int i = 0;i < tmp.length();i++){ //降为小写
if(tmp[i] < 'a'){
tmp[i] += 32;
}
}
if(word.length() == tmp.length()){
for(int i = 0;i < word.length();i++){
if(word[i] == tmp[i]) ++yes;
}
} //如果单词中的一个字母相等,判断值就+1
if(yes == word.length()){
++cnt;
first = true;
} //如果判断值与长度相等,计数器+1
else{
if(!first) continue;
else place += tmp.length();
}
}
if(cnt) cout << cnt << ' ' << place;
else cout << "-1";
return 0;
}
这里空空如也
有帮助,赞一个