《算法笔记》3.3小节——入门模拟->图形输出

@[TOC]

Contest100000577 - 《算法笔记》3.3小节——入门模拟->图形输出

1933 Problem A 输出梯形

来自 http://codeup.cn/contest.php?cid=100000577

#include 
#include 
#include 
using namespace std;

int main()
{
    int h;
    //可能有多组数据,所以为 while循环 
    while(scanf("%d",&h) != EOF)
    {
        int row=h;
        int rowmax = h+2*(h-1);//最底一行字符数 
        for(int i=0;i

1993 Problem B Hello World for U

来自 http://codeup.cn/contest.php?cid=100000577

题解:题目挺绕人,关键是根据提示将其抽象为数学模型,然后用代码展现

//1993ProblemBHello World for U
#include 
#include 
#include 
using namespace std;

int main()
{
    char str[85];//存储字符串
    while(scanf("%s",str) != EOF)//考虑多个测试用例
    {
    //根据提示抽象出字符长度、两边的字符数,空格数==最后一行除去两边的字符数
        int len = strlen(str);//字符长度
        int side = (len+2)/3;//两边的字符数
        int last = len-side*2;//空格数==最后一行除去两边的字符数
        int i;
        for(i=0;i

2003 Problem C 等腰梯形

来自 http://codeup.cn/contest.php?cid=100000577

//2003ProblemC等腰梯形
#include 
#include 
#include 
using namespace std;

int main()
{
    int m;
    while(scanf("%d",&m) != EOF)
    {
        while(m--)
        {
            int h;
            scanf("%d",&h);
            int max = h+2*(h-1);
            //此处特别注意循环的条件,很容易搞错,而且不同的理解
            //参数循环条件也不变 
            for(int i=1;i<=h;i++)//共h行,遍历 
            {
                //对称结构,则空格前后夹击一串* 
                for(int j=h-i;j>0;j--) 
                //每行两边空格各为 h-1,h-2,h-3'''h-h 
                {
                    printf(" ");
                }
                //*符号数为h,h+2,h+4,,,h+2*(i-1) 
                for(int k=1;k<=h+2*(i-1);k++)
                {
                    printf("*");
                }
                for(int j=h-i;j>0;j--)
                {
                    printf(" ");
                }
                //换行 
                printf("\n");
            } 
        }
    }
    return 0;
}

2506 Problem D 沙漏图形 tri2str [1*+]

来自 http://codeup.cn/contest.php?cid=100000577

//2506ProblemD沙漏图形 tri2str [1*+]
#include 
#include 
#include 
using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    int max=2*n-1;
    for(int i=0;i0;i--)//注意此处变量起始值为n-1,去除下方三角形的顶点 
     { 
        //下方正置的三角形 
        for(int j=0;j

你可能感兴趣的:(《算法笔记》3.3小节——入门模拟->图形输出)