hdu2074疊筐解題報告---圖形列印(字串模擬)
阿新 • • 發佈:2018-11-20
疊筐
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 26089 Accepted Submission(s): 6885
Problem Description
需要的時候,就把一個個大小差一圈的筐疊上去,使得從上往下看時,邊筐花色交錯。這個工作現在要讓計算機來完成,得看你的了。
Input
輸入是一個個的三元組,分別是,外筐尺寸n(n為滿足0<n<80的奇整數),中心花色字元,外筐花色字元,後二者都為ASCII可見字元;
Output
輸出疊在一起的筐圖案,中心花色與外筐花色字元從內層起交錯相疊,多筐相疊時,最外筐的角總是被打磨掉。疊筐與疊筐之間應有一行間隔。
思路:一道有點坑的水題
題目大意很簡單,就是用兩種字元圍繞最中間的框符疊筐
通過最中間筐符位置的奇偶性來控制每行每列筐的符號,達到無論從哪個方向看向中心都是交替的效果(仔細看看圖就明白了)。
WA和PE了很久,三個坑點:
1.n = 1時,直接列印內框字元
2.兩個框之間才存在空行,如果後續沒有框輸入了,則沒有空行
3.框的四個角均是空格。
AC Code:
#include<iostream> #include<sstream> #include<cstdlib> #include<cmath> #include<cctype> #include<algorithm> #include<cstring> #include<cstdio> #include<map> #include<vector> #include<stack> #include<queue> #include<set> #include<list> #define mod 998244353 #define INF 0x3f3f3f3f #define Min 0xc0c0c0c0 #define mst(a) memset(a,0,sizeof(a)) #define f(i,a,b) for(int i=a;i<b;i++) using namespace std; typedef long long ll; const int maxn = 1e6 + 5; int main(){ int n; char c1, c2; bool ff = false; while(scanf("%d", &n) != EOF){ getchar(); scanf("%c", &c1); getchar(); scanf("%c", &c2); if(ff) printf("\n"); if(n == 1){ printf("%c\n", c1); continue; } bool flag = false; if((n + 1) / 2 % 2) flag = true; if(flag){ printf(" "); for(int j = 2; j < n; j++){ printf("%c", c1); } printf(" "); printf("\n"); for(int i = 2; i < n; i++){ if(i <= (n + 1) / 2){ for(int j = 1; j <= n; j++){ if(j <= i || j >= n - i + 1){ if(j % 2) printf("%c", c1); else printf("%c", c2); } else { if(i % 2) printf("%c", c1); else printf("%c", c2); } } printf("\n"); } else{ for(int j = 1; j <= n; j++){ if(j <= n - i + 1 || j >= i){ if(j % 2) printf("%c", c1); else printf("%c", c2); } else { if(i % 2) printf("%c", c1); else printf("%c", c2); } } printf("\n"); } } printf(" "); for(int j = 2; j < n; j++){ printf("%c", c1); } printf(" "); } else{ printf(" "); for(int j = 2; j < n; j++){ printf("%c", c2); } printf(" "); printf("\n"); for(int i = 2; i < n; i++){ if(i <= (n + 1) / 2){ for(int j = 1; j <= n; j++){ if(j <= i || j >= n - i + 1){ if(j % 2) printf("%c", c2); else printf("%c", c1); } else { if(i % 2) printf("%c", c2); else printf("%c", c1); } } printf("\n"); } else{ for(int j = 1; j <= n; j++){ if(j <= n - i + 1 || j >= i){ if(j % 2) printf("%c", c2); else printf("%c", c1); } else { if(i % 2) printf("%c", c2); else printf("%c", c1); } } printf("\n"); } } printf(" "); for(int j = 2; j < n; j++){ printf("%c", c2); } printf(" "); } printf("\n"); ff = true; } return 0; }