题意
模拟
思路
注意题目的di*50会让int刚好溢出,所以要用uint
注意精度问题,不能直接用ceil
把取整公式取出即可
原来是ceil((double)x/maxn*50)
变成(x * 50u + maxn - 1) / maxn
代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int,int>
#define fi first
#define se second
int T=1,mod;
int qmi(int a,int b){
int res=1;
while(b){
// if(b&1)res=res*a%mod;
b>>=1;
// a=a*a%mod;
}
return res;
}
inline void Rd(int &res) {
res=0;
int f=1;
char ch=getchar();
while('0'>ch||ch>'9'){
if(ch=='-')f=-1;
ch=getchar();
}
while('0'<=ch&&ch<='9')res=(res<<3)+(res<<1)+(ch-'0'),ch=getchar();
res*=f;
}
int a[110],maxn;
void draw(int x){
int num=(x * 50u + maxn - 1) / maxn;
putchar('+');
for(int i=0;i<num;i++)putchar('-');
putchar('+');
puts("");
putchar('|');
for(int i=0;i<num;i++){
if(i==num-1&&x==maxn){
putchar('*');
break;
}
putchar(' ');
}
putchar('|');
printf("%lld",x);
puts("");
putchar('+');
for(int i=0;i<num;i++)putchar('-');
putchar('+');
puts("");
}
void solve(){
maxn=0;
int n;
Rd(n);
for(int i=0;i<n;i++){
Rd(a[i]);
maxn=max(maxn,a[i]);
}
for(int i=0;i<n;i++){
draw(a[i]);
}
}
signed main(){
// Rd(T);
while(T--){
solve();
}
return 0;
}