找出字符串中首先出現3次的字符

#include <iostream>
using namespace std;
int main()
{
	char str[100];
	cin.get(str, 100);
	int ch[26] = { 0 };
	int i = 0;
	while (str[i] != '\0')
	{
		if (str[i] >= 'a'&&str[i] <= 'z')
		{
			int temp = str[i] - 'a';
			ch[temp]++;
			if (ch[temp] >= 3)
			{
				printf("%c", 'a' + temp);
				break;
			}
		}
		i++;
	}
	return 1;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章