HDU - 2091 空心三角形
题目链接:https://vjudge.net/problem/HDU-2091
这个题没什么好说的,主要就是找规律和考验格式控制,直接看代码吧
#include<set> #include<map> #include<stack> #include<queue> #include<cmath> #include<cstdio> #include<cctype> #include<string> #include<vector> #include<climits> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define max(a, b) (a > b ? a : b) #define min(a, b) (a < b ? a : b) #define mst(a) memset(a, 0, sizeof(a)) #define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n") using namespace std; typedef long long ll; typedef pair<int, int> P; const double eps = 1e-7; const int INF = 0x3f3f3f3f; const ll ll_INF = 233333333333333; const int maxn = 1e3 + 10; int main(void) { char ch; int n, kase = 0; while(~scanf("%c %d%*c", &ch, &n) && ch != '@') { if (kase++) putchar('\n'); //每组输出之间用空行隔开 for (int i = 0; i<n; ++i) { for (int j = 1; j<=n+i; ++j) { if (i != n-1) printf(i+j==n || j-i==n ? "%c" : " ", ch); //输出1到n-1行 通过观察可以发现,除了最后一行ch只出现在i+j和j-i两列 else printf("%c", ch); //输出最后一行 } putchar('\n'); } } return 0;