c++,WA3 5 7 8 9,求佬调!!!
查看原帖
c++,WA3 5 7 8 9,求佬调!!!
1539979
igopor楼主2024/11/24 10:17
#include <bits/stdc++.h>
#include <vector>
#include <limits>
#include <cctype>
using namespace std;
 
 void lo(std::string& str);
 
int main()
{
	string a,b;
	getline(cin,a);//单词 
	string text;
	getline( cin,text );//文章 
	int i,j;
	int c=0;
	lo(a);//转小写 
	lo(text);
	text.insert(text.end(),' ');
	for(i = 0 ; i < text.size() ; i++){
    while(i < text.size() && text[i] == ' '){
        i++;//不是空格就跳出 
    }
    j = i;
    b.clear();//存放文章中单词 
    while(j < text.size() && text[j] != ' '){
        b += text[j];
        j++;
	}//遇到空格就跳出  
    i = j - 1;
    if(a == b){
        c++;//计数器 
    }
}
	if(c!=0){
		cout<<c<<" "<<text.find(a);
	}
	else{
		cout<<-1;
	}
	return 0;
} 


void lo(std::string &str) {
    for (size_t i = 0; i < str.length(); ++i) {
        if (isupper(str[i])) {
            str[i] = tolower(str[i]);
        }
    }
}//copy的转小写函数 
2024/11/24 10:17
加载中...