当前位置:网站首页>String problem summary

String problem summary

2022-06-10 07:29:00 Mulinyou

1. Eating hot pot

This question asks you to check whether there is... In your friend's information “chi1 huo3 guo1”, Count the total number of such information , And record the first occurrence “chi1 huo3 guo1” What is your message .

ordinary find Just go , If there is a subscript that returns the found , If there is no return -1

This question does not make statistics “chi1 huo3 guo1” The total number of times , Just count the total number of messages that appear , It's better to solve this problem .

#include<iostream>
using namespace std;
#include<string>
int main()
{

	string a;
	getline(cin, a);
	int count = 0;
	int temp = -1;
	string b = "chi1 huo3 guo1";
	int num = 1;

	while (a != ".")
	{   
		
		int x=a.find(b);
		if (x != -1)
		{
			count++;
			if (count == 1)
				temp = num;
			
		}

		getline(cin, a);
		num++;
	}
	if (count == 0)
		cout << "-_-#";
	else
		cout << temp<<" "<<count;


}

原网站

版权声明
本文为[Mulinyou]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203021113330627.html