题目链接: F-DPS
Description
题意:给出一组序列,输出伤害面板图表
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 n players in the game. Given that the i-th player dealt di damage to enemies where maxidi > 0max >0 is granted, you need to calculate the number si of spaces in the bar by the following foluma:
si = 50 * (di/maxidi)
Instead of formal definition of bar description, we will give an example. For some player i whose si = 7 and di = 777, 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.
Input
- The first line contains one integer n(1 <= n <= 100);
- The next n line each contains one integer, the i-th line contains di(0 <= di <= 43962200);
- It’s granted that maxidi > 0;
Output
3n lines, each 3 lines denote a bar in the correct format.
Sample Input
4
50
40
50
0
Sample Output
±-------------------------------------------------+
| *|50
±-------------------------------------------------+
±---------------------------------------+
| |40
±---------------------------------------+
±-------------------------------------------------+
| *|50
±-------------------------------------------------+
++
||0
++
Method
- 显然,算出 si 和 maxidi 即可知道 ‘-’ 的长度,但是需要注意向上取整的问题,用ceil向上取整会wa,建议手动向上取整,
- s = (50LL*d[i]+maxn-1)/maxn;
Code
详见注释
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
#define ios std::ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);
#define rtxt freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define ll long long
const int Max = 1e2+3;
const int mod = 1e9+7;
ll n, d[Max];
ll maxn;
int main()
{
ios
cin >> n;
maxn = 0;
for(int i=1; i<=n; i++)
{
cin >> d[i];
maxn = max(maxn, d[i]);
}
ll s;
for(int i=1; i<=n; i++)
{
s = (50LL*d[i]+maxn-1)/maxn;
//s = ceil(t);
cout << "+";
for(int j=1; j<=s; j++)
cout << "-";
cout << "+\n";
cout << "|";
for(int j=1; j<=s; j++)
{
if(j == s&&maxn == d[i]) cout << "*";
else cout << " ";
}
cout << "|" << d[i] << endl;
cout << "+";
for(int j=1; j<=s; j++)
cout << "-";
cout << "+\n";
}
return 0;
}
蒟蒻一只,欢迎指正