| 比赛 | 
    防止颓废的小练习v0.15 | 
    评测结果 | 
    AAWAWWWWWW | 
    | 题目名称 | 
    统计单词数 | 
    最终得分 | 
    30 | 
    | 用户昵称 | 
    WHZ0325 | 
    运行时间 | 
    0.286 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    0.31 MiB  | 
    | 提交时间 | 
    2016-10-17 21:00:02 | 
显示代码纯文本
#include <fstream>
#include <string>
#include <cctype>
#include <vector>
using namespace std;
ifstream fin("stat.in");
ofstream fout("stat.out");
inline void s_tolower(string &s) {
	for(unsigned int i=0;i<s.length();i++) {
		s[i]=tolower(s[i]);
	}
}
string s;
vector<string> v;
int main() {
	fin>>s;
	s_tolower(s);
	bool first=true;
	int out=0;
	int first_out;
	
	string get_s;
	getline(fin,get_s,char(EOF));
	int last=1;
	for(unsigned int i=1;i<get_s.length();i++) {
		if((i==get_s.length()-1)||(get_s[i]==' '&&get_s[i+1]!=' ')) {
			v.push_back(get_s.substr(last,i-last));
			if(v.back()[v.back().length()-1]==' ') {
				v.push_back(v.back());
			}
			last=i+1;
		}
	}
	for(unsigned int i=0;i<v.size();i++) {
		s_tolower(v[i]);
		if(s==v[i]) {
			if(first) {
				first_out=i;
				first=false;
			}
			out++;
		}
	}
	if(out==0) {
		fout<<"-1"<<endl;
	}
	else {
		fout<<out<<" "<<first_out<<endl;
	}
	fin.close();
	fout.close();
	return 0;
}