赞
踩
- #include<stdio.h>
-
- //统计字符串中大写字母的出现次数
- void AlphabetCounting(char _arr[])
- {
- int count[26] = {0};
- int i = 0;
-
- while(_arr[i]!='\0')
- {
- if (_arr[i] >= 'A'&&_arr[i] <= 'Z')
- {
- ++count[_arr[i] - 'A']; //将A-Z的个数存放到下标所对应元素中
- }
- i++;
- }
- for (i = 0; i<26; ++i)
- {
- printf("%c = %d ", 'A' + i,count[i]);
- if ((i + 1) % 6 == 0)
- cout << endl;
- }
- }
-
- int main()
- {
- char arr[] = "ABCBFVYU diufvbi CYVUBUHJBJTFCG";
- AlphabetCounting(arr);
- return 0;
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。