- 最後登錄
- 2022-10-28
- 在線時間
- 0 小時
- 註冊時間
- 2010-2-3
- 閱讀權限
- 30
- 精華
- 0
- UID
- 7563378
- 帖子
- 722
- 積分
- 2721 點
- 潛水值
- 16557 米
| - #include <stdlib.h>
- #include <iostream>
- #include <string>
- using namespace std;
- enum{
- NUM = 0,
- UPPER,
- LOWER,
- CHINESE,
- COUNT
- };
- int main()
- {
- setlocale( LC_ALL, "cht" );
- cout << "請輸入原始字串:";
- string str;
- getline( cin, str );
- int counter[COUNT] = { 0 };
- unsigned char c = 0;
- for( int i=0; i<str.length(); ++i ){
- c = str[i];
- if( c >= '0' && c <= '9' ){
- ++counter[NUM];
- }
- else if( c >= 'A' && c <= 'Z' ){
- ++counter[UPPER];
- }
- else if( c >= 'a' && c <= 'z' ){
- ++counter[LOWER];
- }
- else if( c >= 0x80 ){
- ++counter[CHINESE];
- ++i;
- }
- }
-
- char* text[COUNT] = { "數字:","大寫:","小寫:","中文:" };
- for( int i=0; i<COUNT; ++i ){
- cout << text[i] << counter[i] << endl;
- }
- system( "pause" );
- return 0;
- }
複製代碼 ... |
|