- 分享
- 0
- 人气
- 0
- 主题
- 7
- 帖子
- 4707
- UID
- 82675
- 积分
- 5108
- 阅读权限
- 22
- 注册时间
- 2007-6-18
- 最后登录
- 2021-7-27
- 在线时间
- 5767 小时
|
剛用 VC.NET 寫了個簡單點的
- #include<iostream>
- using namespace std;
- int main()
- {
- int i = 0, iVowels = 0, iSpaces = 0, iConsonants = 0, iCapital = 0, iSmall = 0, iNumeric = 0;
- const int ilen = 50;
- char cText[ilen], cSingle;
- cout << "Enter the sentense : ";
- cin.get(cText, ilen);
- cout << "Accepted sentense : " << cText << "\n";
- while(cSingle = cText[i++])
- {
- int iASC = cSingle;
- if(iASC >= 65 && iASC <= 90)
- iCapital++;
- else if(iASC >= 97 && iASC <= 122)
- iSmall++;
- else if(iASC >= 48 && iASC <= 57)
- iNumeric++;
- switch(tolower(cSingle))
- {
- case 'a':
- case 'e':
- case 'i':
- case 'o':
- case 'u':
- iVowels++;
- break;
- case ' ':
- iSpaces++;
- break;
- default:
- iConsonants++;
- break;
- }
- }
- cout << "Count of vowels = " << iVowels << "\n";
- cout << "Count of spaces = " << iSpaces << "\n";
- cout << "Count of consonants = " << iConsonants << "\n";
- cout << "Count of capital letters = " << iCapital << "\n";
- cout << "Count of small letters = " << iSmall << "\n";
- cout << "Count of numeric = " << iNumeric << "\n";
- system("pause");
- return 0;
- }
复制代码
[ 本帖最后由 Super-Tomato 于 2008-10-20 02:14 AM 编辑 ] |
-
总评分: 积分 + 5
查看全部评分
|