2020牛客暑期多校训练营(第五场)F

DPS

https://ac.nowcoder.com/acm/contest/5670/F

题目描述

  When you are playing multiplayer games, you may want to show that you are the MVP of your team or blame the one always wandering and watching away from the storm center. Well, there're statistics that show you preformance, but sometimes numbers speak softer than charts. Now, you're hired to write a program that output ASCII art histograms showing damage dealt to enemies.
  There are players in the game. Given that the -th player dealt damage to enemies where is granted, you need to calculate the number of spaces in the bar by the following foluma: . Instead of formal definition of bar description, we will give an example. For some player i whose and , the bar is shown as:

+-------+
|       |777
+-------+

  Moreover, you have to mark the player with maximal damage dealt to enemies by replacing the last space into *. If there're multiple maximum, mark all of them.
  See samples for more ideas.

输入描述

  The first line contains one integer .
  The next line each contains one integer, the -th line contains .
  It's granted that .

输出描述

   lines, each lines denote a bar in the correct format.

示例1

输入

4
50
40
50
0

输出

+--------------------------------------------------+
|                                                 *|50
+--------------------------------------------------+
+----------------------------------------+
|                                        |40
+----------------------------------------+
+--------------------------------------------------+
|                                                 *|50
+--------------------------------------------------+
++
||0
++

示例2

输入

5
1676
4396
2200
443
556

输出

+--------------------+
|                    |1676
+--------------------+
+--------------------------------------------------+
|                                                 *|4396
+--------------------------------------------------+
+--------------------------+
|                          |2200
+--------------------------+
+------+
|      |443
+------+
+-------+
|       |556
+-------+

分析

  按照题意模拟即可。
  需要注意细节:计算 时会爆 ;最大值在直方图中要作出标记; 要紧靠直方图输出,并在第二行输出。

代码

/******************************************************************
Copyright: 11D_Beyonder All Rights Reserved
Author: 11D_Beyonder
Problem ID: 2020牛客暑期多校训练营(第五场) Problem F
Date: 8/16/2020
Description: Simulation
*******************************************************************/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=105;
int n;
ll d[N];
bool is[N];
int s[N];
int main(){
    ll MAX=-1;
    int i,j;
    cin>>n;
    for(i=1;i<=n;i++){
        scanf("%lld",&d[i]);
        MAX=max(d[i],MAX);
    }
    for(i=1;i<=n;i++){
        is[i]=d[i]==MAX;//是最大值
        s[i]=ceil(50.0/MAX*d[i]);
    }
    for(i=1;i<=n;i++){
        //第一行
        putchar('+');
        for(j=1;j<=s[i];j++){
            putchar('-');
        }
        putchar('+');
        putchar('\n');
        //第二行
        putchar('|');
        for(j=1;j<=s[i]-is[i];j++){
            putchar(' ');
        }
        if(is[i]) putchar('*');
        putchar('|');
        printf("%lld\n",d[i]);
        //第三行
        putchar('+');
        for(j=1;j<=s[i];j++){
            putchar('-');
        }
        putchar('+');
        putchar('\n');
    }
    return 0;
}
牛客暑期多校训练营题解 文章被收录于专栏

收集牛客暑期多校训练营的题解

全部评论

相关推荐

2025-12-05 19:18
已编辑
门头沟学院 Java
化尽纤尘:hr挂了,这公司迟早倒闭,技术人员不注重技术在那里搞服从性测试,必须满足它那**思想,钱也给的不多还要“自主学习”
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务