话说用getline写不是也要个回车吗 我这么写为什么就超时
查看原帖
话说用getline写不是也要个回车吗 我这么写为什么就超时
1413607
QLK31415926楼主2024/8/20 22:08
// P1308 [NOIP2011 普及组] 统计单词数 -- 字符串题库
#include<bits/stdc++.h>

using namespace std;
string lower(string);

int main()
{	
	string word, passage;
	int i = 0, time = 0, location = 1000001;
	
	cin >> word;
	
	word = lower(word);
	
	do
	{
		cout << '\b';
		cin >> passage;
		passage = lower(passage);
		if(word == passage) 
		{
		location = location < i ? location : i;
		time ++;
		}
		i ++;
	}
    while(cin.get() != '\n');
	
	if (time) printf("%d %d", time, location);
	else printf("-1");
	return 0;
}

string lower(string str)
{
	for (int i = 0 ; i < str.length() ; i ++ )
	{
		str[i] = str[i] > 'Z' ? str[i] : (str[i] + 32);
	}
	return str;
}
2024/8/20 22:08
加载中...