当前位置:编程学习 > C/C++ >>

九度OJ1098 字母统计

题目分析:

使用两个数组分别存储字母表和对应的字母出现次数。

 


源代码:


[cpp]
#include<iostream>  
#include<string>  
using namespace std; 
 
int main() 

    char ch[30] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; 
    string s; 
    while (cin>>s) 
    { 
        int num[30] = {0}; 
        for (int i = 0; i < s.length(); i++) 
        { 
            switch (s[i]) 
            { 
            case 'A': 
                num[0] ++; 
                break; 
            case 'B': 
                num[1] ++; 
                break; 
            case 'C': 
                num[2] ++; 
                break; 
            case 'D': 
                num[3] ++; 
                break; 
            case 'E': 
                num[4] ++; 
                break; 
            case 'F': 
                num[5] ++; 
                break; 
            case 'G': 
                num[6] ++; 
                break; 
            case 'H': 
                num[7] ++; 
                break; 
            case 'I': 
                num[8] ++; 
                break; 
            case 'J': 
                num[9] ++; 
                break; 
            case 'K': 
                num[10] ++; 
                break; 
            case 'L': 
                num[11] ++; 
                break; 
            case 'M': 
                num[12] ++; 
                break; 
            case 'N': 
                num[13] ++; 
                break; 
            case 'O': 
                num[14] ++; 
                break; 
            case 'P': 
                num[15] ++; 
                break; 
            case 'Q': 
                num[16] ++; 
                break; 
            case 'R': 
                num[17] ++; 
                break; 
            case 'S': 
                num[18] ++; 
                break; 
            case 'T': 
                num[19] ++; 
                break; 
            case 'U': 
                num[20] ++; 
                break; 
          

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,