本文介绍了我的计划有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串,需要确定两个辅音之间包含的元音数量。

例如:

输入:水沸腾百度。 br />
输出:5



说明:唯一遵守规则的元音是:

'a'和' e'来自水,'u'和'e'来自百度,第一个'e'来自度数。



我尝试过:



I have a string and need to determine the number of vowels that are included between two consonants.
Eg:
Input:Water boils at one hundred degrees.
Output:5

Explication:The only vowels that respect the rule are:
'a' and 'e' from water,'u' and 'e' from hundred and the first 'e' from degrees.

What I have tried:

#include<stdio.h>
bool vowel(char c)
{
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
		return true;
	else
		return false;

}
bool consonant(char c)
{
	if (c >= 'a'&&c <= 'z'&&vowel(c) == false)
		return true;
	else
		return false;
}
int main()
{
	char S[256];
	int i;
	int nr = 0;
	scanf_s("%s", S);
	for (i = 1; S[i]!=EOF; i++)
		if (vowel(S[i]) == true && consonant(S[i - 1]) == true && consonant(S[i + 1]) == true)
			nr++;
	printf("%d", nr);

	system("pause");
	return 0;
}

推荐答案

typedef int bool;

#define true  1
#define false 0

最后,如果你想读一行含有多个单词的文字得到(S);是个不错的选择。它会读取字符,直到收到换行符或EOF。

Lastly, if you want to read a line of text containing multiple words gets( S ); is a good option. It reads characters until a newline or EOF is received.


引用:

但是当我在c ++上创建这个程序时,我发现当我用w作为大写字母写Water时, a'不尊重规则。

However when i made this programm on c++,i found out that when for example i write "Water" with w as capital letter,'a' doesn't respect the rule.



因为你的代码只是小写,你需要在你的代码中添加大写字母。


Because your code is only lowercase, you need to add uppercase to your code.

引用:

其次,在c ++中可以将EOF定义为空字符吗?

Secondly,in c++ can EOF be defined as null character?



是的,您可以将EOF定义为0 char ,只需将其包含在您的代码中。

[]

[]



这篇关于我的计划有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 19:59
查看更多