本文的目的是实现一个程序,用于打印给定字符串中驼峰字符的数量。
As you all know, a string is a collection of characters. Now let us see what camel case letters are.
像Java这样的编程语言使用一种称为驼峰命名法的命名风格。也就是说,它在输入多个单词的标识时不使用空格或下划线,将首个单词小写,后续单词大写。以这种方式编写的代码更易于阅读和理解。
The inner uppercase letters, which resemble camel humps, are what give the name of the font its meaning. WordPerfect, FedEx, and ComputerHope are a few examples of camel case characters.
除此之外,驼峰命名法指的是在编写复合词或句子时不使用空格或标点符号。相反,每个不同的单词通过使用小写或大写字母来表示(例如,PlayStation)。
提供的字符串中大写字母的总数是驼峰命名字符的定义。
Sample Example 1
Let us take the input string str = “asKKVrvAN"
登录后复制
The output we get is 2.
登录后复制
Explanation
的翻译为:
解释
给定的字符串str中出现的驼峰式字符为K、K、V、A和N。
示例示例2
Let us take the input string str = “fhgUBHII”
登录后复制
The output we get is 5.
登录后复制登录后复制
Explanation
的翻译为:
解释
给定字符串str中存在的驼峰字符为U、B、H、I和I。
Sample Example 3
Let us take the input string str = “nbdGONYL”
登录后复制
The output we get is 5.
登录后复制登录后复制
Explanation
的翻译为:
解释
给定字符串str中存在的驼峰命名字符为G, O, N, Y和L。
Sample Example 4
Let us take the input string str = “xyz”
登录后复制
The output we get is 0.
登录后复制
Explanation
的翻译为:
解释
There are no Camel case characters that are present in the given string str.
Problem Statement
Implement a program to print the number of camel case character present in a given string.
Solution Approach
为了打印给定字符串中驼峰字符的数量,我们采用以下方法。
解决这个问题并打印给定字符串中驼峰命名字符的数量的方法是基于ASCII值的。对于对ASCII值了解很少的初学者,这里是定义。
每个字符变量都被赋予一个介于0和127之间的数字作为其ASCII值,该值代表变量的数值。
Uppercase letters A–Z have an ASCII value range of 65–90, while lowercase letters a–z have a value range of 97–122.
也就是说,大写字母A的ASCII码或ASCII值为65,B为66,C为67,依此类推。字母Z的ASCII值为90。
因此,通过迭代提供的字符串并计算所有ASCII值在[65, 91]之间的字符,可以解决所述问题。一旦计数完成,我们打印输出,即在确保所有字符都存在后打印完整计数。
算法
给定字符串中打印驼峰字符数量的算法如下所示
Step 1 − Start
第二步 – 定义一个字符串
第三步 – 将计数设置为零
步骤 4 – 遍历字符串以检查 ASCII 值
Step 5 − If the ASCII value of the letter
lies in between the range [65, 90] then we increment the count otherwise ignore.
步骤 6 − 获取驼峰命名字符的总数,并打印输出
Step 7 − Stop
Example: C Program
在这里,您可以找到上述编写的算法的C程序实现,用于打印给定字符串中驼峰字符的数量。
#include #include int main(){ char str[]= "abcdEFGH"; // Stores the total number of camel case letters count is set to 0 int count = 0; // Traversing the string for (int i = 0; str[i]; i++) { // Check whether ASCII value of the //letter // lies in between the range [65, 90] // then we increment the count if (str[i] >= 65 && str[i]输出
total count of camel case letters acquired: 4登录后复制
结论
同样地,我们可以打印出任何给定字符串中驼峰字符的数量。在本文中解决了获取给定字符串中驼峰字符数量的挑战。这里提供了C编程代码以及打印给定字符串中驼峰字符数量的算法。
以上就是在给定的字符串中,存在驼峰命名法字符的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2585335.html