HDU 2091 空心三角形 --- 水题

/* HDU 2091 空心三角形 --- 水题 */
#include <cstdio>

int main()
{
    int kase = 0;
    char ch;
    int h, t; //h表示高
    while (scanf("%c", &ch) == 1 && ch != ‘@‘){
        scanf("%d", &h);
        if (kase++){
            printf("\n");
        }
        getchar();
        if (h == 1){
            //注意1的时候特殊处理
            printf("%c\n", ch);
            continue;
        }

        //第一行
        for (int i = 0; i < h - 1; ++i)
            printf(" ");
        printf("%c\n", ch);
        //2 - h-1行
        for (int i = 2; i < h; ++i){
            //n-i个空
            t = h - i;
            for (int j = 0; j < t; ++j)
                printf(" ");
            printf("%c", ch);
            //2(i-2)+1个空
            t = 2 * (i - 2) + 1;
            for (int j = 0; j < t; ++j){
                printf(" ");
            }
            printf("%c\n", ch);
        }
        //n行
        t = 2 * h - 1;
        for (int i = 0; i < t; ++i)
            printf("%c", ch);
        printf("\n");
    }

    return 0;
}

时间: 2024-12-25 03:16:18

HDU 2091 空心三角形 --- 水题的相关文章

hdu 2091 空心三角形

这题还是比较坑的首先要注意两点: 1.行末没有多余的空格; 2.就是当n==1的时候单独判断; #include <iostream> using namespace std; int main() { char ch; int n,flag=0; while(cin>>ch) { if(ch=='@') break; cin>>n; if(flag) cout<<endl; flag=1; if(n==1) { cout<<ch<<

简单的dp hdu 数塔(水题)

数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 21314    Accepted Submission(s): 12808 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少

hdu 2053 Switch Game 水题一枚,鉴定完毕

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10200    Accepted Submission(s): 6175 Problem Description There are many lamps in a line. All of them are off at first. A series of op

HDU 2090 算菜价 --- 水题

/* HDU 2090 算菜价 --- 水题 */ #include <cstdio> int main() { char s[105]; double a, b, sum = 0; while (scanf("%s", s)==1){ scanf("%lf%lf", &a, &b); a *= b; sum += a; } printf("%.1f\n", sum); return 0; }

hdu 2212 DFS(水题)

DFS Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4923    Accepted Submission(s): 3029 Problem Description A DFS(digital factorial sum) number is found by summing the factorial of every digit

hdoj 2091 空心三角形

空心三角形 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 29368    Accepted Submission(s): 8074 Problem Description 把一个字符三角形掏空,就能节省材料成本,减轻重量,但关键是为了追求另一种视觉效果.在设计的过程中,需要给出各种花纹的材料和大小尺寸的三角形样板,通过电脑临时做出来,

hdu 5007(字符串水题)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5007 Post Robot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 327    Accepted Submission(s): 253 Problem Description DT is a big fan of digital

HDOJ/HDU 2560 Buildings(嗯~水题)

Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, the green grids represent the buidings. Given the size of the HZNU Campus, and the color of each grid, you should count how many green grids in the N

HDU 3316 爆搜水题

爆搜水题 模拟扫雷,规则和扫雷一样 给出原图,求在X,Y位置点一下以后的图形,没有弹出的点输出-1,弹出的点输出这个点的数字 从起始点DFS一下即可 #include "stdio.h" #include "string.h" int dir[8][2]={ {-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1} }; int n; int hash[110][110]; char str[110][110]; i