模拟
C. Cardiogram time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output
In this problem, your task is to use ASCII graphics to paint a cardiogram.
A cardiogram is a polyline with the following corners:
That is, a cardiogram is fully defined by a sequence of positive integers a1, a2, ..., an.
Your task is to paint a cardiogram by given sequence ai.
Input
The first line contains integer n (2 ≤ n ≤ 1000). The next line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 1000). It is guaranteed that the sum of all ai doesn't exceed 1000.
Output
Print max |yi - yj| lines (where yk is the y coordinate of the k-th point of the polyline), in each line print
characters. Each character must equal either « / » (slash), « \ » (backslash), « » (space). The printed image must be the image of the given polyline. Please study the test samples for better understanding of how to print a cardiogram.
Note that in this problem the checker checks your answer taking spaces into consideration. Do not print any extra characters. Remember that the wrong answer to the first pretest doesn't give you a penalty.
Sample test(s) input
5
3 1 2 5 1
output
/ \
/ \ / \
/ \
/ \
\ /
input
3
1 5 1
output
/ \
\
\
\
\ /
Note
Due to the technical reasons the answers for the samples cannot be copied from the statement. We've attached two text documents with the answers below.
http://assets.codeforces.com/rounds/435/1.txt
http://assets.codeforces.com/rounds/435/2.txt
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,a[1100];
char mp[10000][10000];
int main()
{
scanf("%d",&n);
int X=0,Y=0,high=0,low=0;
for(int i=0;i<n;i++)
{
scanf("%d",a+i);
X+=a[i];
Y+=a[i]*(i%2==0?1:-1);
high=max(Y,high);
low=min(Y,low);
}
int x=high,y=0;
memset(mp,32,sizeof(mp));
for(int i=0;i<n;i++)
{
for(int j=0;j<a[i];j++)
{
if(i%2==0)
{
mp[x][y]='/';
y++; x--;
}
else
{
mp[x][y]='\\';
y++; x++;
}
}
if(i%2==0) x++; else x--;
}
for(int i=1;i<=high-low;i++)
{
for(int j=0;j<X;j++)
{
printf("%c",mp[i][j]);
}
putchar(10);
}
return 0;
}