我是靠谱客的博主 殷勤时光,最近开发中收集的这篇文章主要介绍C. Cardiogram,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <cmath>


using namespace std;


#define maxn 2010
char g[maxn][maxn];


int main()
{




    memset(g,' ',sizeof(g));
    int num = 0;
    int miny = 1000, maxy = 1000;//最大值最小值都要初始成1000
    int  x = 0, y = 1000,n = 0;
    int d = 1;


    scanf("%d",&n);
    for( int i = 0; i<n; i++)
    {
        scanf("%d",&num);
        while( num--)
        {
            if( d == 1)
              g[y][x++] = '/';
            else
              g[y][x++] = '\';
            y += d;


        }
        y -= d;//注意每当方向改变时,与上一次最后一个一行;
        d = -d;
        maxy = max(maxy,y);
        miny = min(miny,y);


    }
    for (int i = maxy; i >= miny; --i)
    {
        g[i][x]=0;//加入字符串结束标准,要不然无法用puts
        puts(g[i]);
    }
  //  scanf("%d",&n);
    return 0;
}

最后

以上就是殷勤时光为你收集整理的C. Cardiogram的全部内容,希望文章能够帮你解决C. Cardiogram所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(70)

评论列表共有 0 条评论

立即
投稿
返回
顶部