好久不见!
两年备考生涯伤不起QAQ
原题地址:https://pintia.cn/problem-sets/994805260223102976/problems/994805280817135616
今天来教大家玩一下ASCII码。
在ASCII中,大家可以把下面几个背下来,用得着。
而且用的时候,别人眼中会出现小星星。
a ~ z : 97 ~122
A ~ Z: 65 ~ 90
0 ~ 9: 48 ~ 57
记得当年,数据结构实验课上,有位同学问我,
为什么他的二叉树遍历后的序列是一串数字。
我看了看他输入的构建二叉树的序列“XXX……A……XXX”,又看了看那串遍历后的序列“65*****************”。
于是,把他的源代码拉到头,将存储结构的int改成char,留下一句“好了。”
转身离去,深藏功与名。
代码如下:
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<bitset>
#include<fstream>
#include<sstream>
using namespace std;
int arr[27]; //arr[0]无用,arr[1]~arr[26]分别对应26个字母出现次数
int main()
{
string s;
getline(cin, s);
for (char c : s) {
if (65 <= c && c <= 90)
c += 32; //大写转换为小写
if (97 <= c && c <= 122)
arr[(int)c - 96]++; //如果是小写字母(不论是否经过转换),在arr[]中计数
}
int max = 0, index = 0;
for (int i = 1; i != 27; ++i) //找最大小写字母
if (arr[i] > max) {
max = arr[i];
index = i;
}
cout << char(index + 96) << ' ' << max << endl; //arr下标1~26,a~z的ASCII为97~122
return 0;
}