文章

21

粉丝

0

获赞

19

访问

4.8k

头像
显示柱状图 题解:
P5363 四川大学2024年机试题
发布于2026年3月27日 16:21
阅读数 214

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

int main() {
	int n, x = 0;
	cin >> n;
	int top = 0, bot = 0; // 记录最高和最低
	vector<string> map(31, string(n * 2 - 1, ' '));
	map[15] = string(n * 2 - 1, '-'); // 坐标轴
	string s;
	
	while(n--){
		cin >> s;
		int sn = s.size();
		// 根据输入长度判断输入情况
		if(sn == 1){
			int y = s[0] - '0';
			if(y > top) top = y;
			for(int i = 0; i < y; i++)
				map[14 - i][x] = '+';
			x += 2;
		}
		else if(sn == 2){ // 长度为二时有两种情况
			if(s[0] == '-'){
				int y = s[1] - '0';
				if(y > bot) bot = y;
				for(int i = 0; i < y; i++)
					map[16 + i][x] = '+';
				x += 2;
			}
			else{
				int y = s[0] - '0';
				char c = s[1];
				if(y > top) top = y;
				for(int i = 0; i < y; i++)
					map[14 - i][x] = c;
				x += 2;
			}
		}
		else if(sn == 3){
			int y = s[1] - '0';
			char c = s[2];
			if(y > bot) bot = y;
			for(int i = 0; i < y; i++)
					map[16 + i][x] = c;
			x += 2;...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发