本文的目的是實作一個程序,用於列印給定字串中駝峰字元的數量。
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.
範例範例2
Let us take the input string str = “fhgUBHII”
The output we get is 5.
Sample Example 3
Let us take the input string str = “nbdGONYL”
The output we get is 5.
的翻譯為:
解釋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.
為了列印給定字串中駝峰字元的數量,我們採用以下方法。
每個字元變數都被賦予一個介於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.因此,透過迭代提供的字串並計算所有ASCII值在[65, 91]之間的字符,可以解決所述問題。一旦計數完成,我們列印輸出,即在確保所有字元都存在後列印完整計數。
演算法
#include <stdio.h> #include <string.h> 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]<=90) count++; } // Print the output as the total count of camel case letters acquired printf("total count of camel case letters acquired: "); printf("%d",count); return 0; }###輸出###
total count of camel case letters acquired: 4###結論### ###同樣地,我們可以列印任何給定字串中駝峰字元的數量。在本文中解決了獲取給定字串中駝峰字元數量的挑戰。這裡提供了C程式碼以及列印給定字串中駝峰字元數量的演算法。 ###
以上是在給定的字串中,存在駝峰命名法字符的詳細內容。更多資訊請關注PHP中文網其他相關文章!