HDU 2074 疊筐

來源:互聯網
上載者:User
疊筐

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10111 Accepted Submission(s): 2548

Problem Description需要的時候,就把一個個大小差一圈的筐疊上去,使得從上往下看時,邊筐花色交錯。這個工作現在要讓電腦來完成,得看你的了。

Input輸入是一個個的三元組,分別是,外筐尺寸n(n為滿足0<n<80的奇整數),中心花色字元,外筐花色字元,後二者都為ASCII可見字元;

Output輸出疊在一起的筐圖案,中心花色與外筐花色字元從內層起交錯相疊,多筐相疊時,最外筐的角總是被打磨掉。疊筐與疊筐之間應有一行間隔。

Sample Input

11 B A5 @ W

Sample Output

 AAAAAAAAA ABBBBBBBBBAABAAAAAAABAABABBBBBABAABABAAABABAABABABABABAABABAAABABAABABBBBBABAABAAAAAAABAABBBBBBBBBA AAAAAAAAA  @@@ @WWW@@W@W@@WWW@ @@@ 

 總結: 這道題 水題一道,關鍵有三點要注意 1:中間的花色問題,我們用m=(n-1)/2;m=m%2來控制中間的花色;2:要留意n==1的情況, WA了好幾次,最後仔細檢查了一下,才發現少了這種情況;3:WA的問題解決之後有出現了PE問題,在仔細看看題才知道,只是在疊筐與疊筐之間(即兩個輸出之間)才有空行。

 

import java.util.*;import java.io.*;public class T2074 {public static void main(String[] args) {Scanner sc = new Scanner(new BufferedInputStream(System.in));int bh=0;while (sc.hasNext()) {int n = sc.nextInt();String s1 = sc.next();String s2 = sc.next();// 控制疊筐與疊筐之間(即兩個輸出之間)的空行if(bh==0) bh=1;else{System.out.println();}String str[][] = new String[81][81];//控制中間的花色int m = (n - 1) / 2;if (m % 2 != 0) {String t;t = s1;s1 = s2;s2 = t;}//分兩種情況,n==1和n!=1的情況if (n == 1)System.out.println(s1);else {String st = " ";for (int i = 0; i < n - 2; i++) {st += s1;}st += " ";str[0][0] = st;boolean bb = true;for (int i = 1; i <= n / 2; i++) {boolean b = true;int k = 0;for (int j = 1; j <= i; j++) {if (b == true) {b = false;str[i][k++] = s1;} else {b = true;str[i][k++] = s2;}}if (bb) {bb = false;for (int j = i; j < n - i; j++) {str[i][k++] = s2;}} else {bb = true;for (int j = i; j < n - i; j++) {str[i][k++] = s1;}}for (int j = 1; j <= i; j++) {if (b == false) {b = true;str[i][k++] = s1;} else {b = false;str[i][k++] = s2;}}}for (int i = 0; i <= n / 2; i++) {for (int j = 0; j < n; j++) {if (str[i][j] != null)System.out.print(str[i][j]);}System.out.println();}for (int i = n / 2 - 1; i >= 0; i--) {for (int j = 0; j < n; j++) {if (str[i][j] != null)System.out.print(str[i][j]);}System.out.println();}}}}}

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.