0
点赞
收藏
分享

微信扫一扫

P1598 垂直柱状图

穆熙沐 2022-02-06 阅读 60

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;

string s;
int temp,STEMP;
int num[30];
int TEMP[30];
char word[27] = {'a', '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'};

int main() {
	for (int i = 0; i < 4; i++) {
		getline(cin,s);
		for (int i = 0; i < s.length(); i++) {
			if (s[i] >= 'A' && s[i] <= 'Z') {
				temp = s[i] - 64;
				num[temp]++;
				TEMP[temp]++;
			}
		}
	}
	sort(TEMP, TEMP + 27);
	STEMP = TEMP[26];
	for (int i = 1; i <= TEMP[26]+1; i++) {
		for (int j = 1; j <= 26; j++) {
			if (num[j] < STEMP &&  STEMP!=0) {
				if (j <= 25)
					cout << "  ";
				else
					cout << " ";
			}
			else if (num[j] >= STEMP && STEMP != 0) {
				if (j <= 25)
					cout << "* ";
				else
					cout << "*";
			}
			else if (STEMP == 0) {
				if (j <= 25) {
					cout << word[j] << " ";
				}
				else {
					cout << word[j];
				}
			}
		}
		STEMP--;
		cout << endl;
	}
	system("pause");
	return 0;
}
举报

相关推荐

0 条评论