zoukankan      html  css  js  c++  java
  • HDOJ(HDU) 2153 仙人球的残影(谜一样的题、、、)

    Problem Description
    在美丽的HDU,有一名大三的同学,他的速度是众所周知的,跑100米仅仅用了2秒47,在他跑步过程中会留下残影的哎,大家很想知道他是谁了吧,他叫仙人球,既然名字这样了,于是他的思想是单一的,他总是喜欢从一点出发,经过3次转折(每次向右转90°),回到出发点,而且呢,他每次转折前总是跑相同长度的路程,所以很多人都想知道如果用‘1’算他跑步出发的第一个残影的话,那么回到起点的时候,他的残影是怎么样的呢?
     

    Input
    测试数据有多行,每一行为一个数N(1<=N<=10)(以0结尾,0不做处理),即仙人球在没有回到起点的时候,跑过留下N个残影后突然90°右转。
     

    Output
    每组测试数据输出一个结果,并且每个残影的计数位长度为3个字符长度。(当然N等于1的话,它的结果也是占用3个字符位置的)
     

    Sample Input
    4
     

    Sample Output
    1 2 3 4 12 5 11 6

    10 9 8 7




    题目有点坑啊,。。n竟然可以为0,搞得我WA了几次、、一定要有一个判断n<=0,break的、不然会WA、


    import java.util.Scanner;
    
    public class Main{
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		while(sc.hasNext()){
    			int n =sc.nextInt();
    			if(n<=0){
    				break;
    			}
    			if(n==1){
    				System.out.println("  1");
    				continue;
    			}
    			//上面的数字
    			int up[] = new int[n];
    			//下面的数字
    			int down[] = new int[n];
    			//右边的数字
    			int right[] = new int[n-2];
    			//左边的数字
    			int left[] = new int[n-2];
    			int t=1;
    			for(int i=0;i<n;i++){
    				up[i]=t;
    				t++;
    			}
    			for(int i=0;i<n-2;i++){
    				right[i]=t;
    				t++;
    			}
    			for(int i=0;i<n;i++){
    				down[i]=t;
    				t++;
    			}
    			for(int i=0;i<n-2;i++){
    				left[i]=t;
    				t++;
    			}
    			int r=0;
    			int f=n-3;
    			for(int i=0;i<n;i++){
    				
    				for(int j=0;j<n;j++){
    					if(i==0){
    						System.out.printf("%3d",up[j]);
    					}else if(i==n-1){
    						System.out.printf("%3d",down[n-1-j]);
    					}else{
    						if(j==0){
    							System.out.printf("%3d",left[f]);
    							f--;
    						}else if(j==n-1){
    							System.out.printf("%3d",right[r]);
    							r++;
    						}else{
    							System.out.print("   ");
    						}
    					}
    				}
    				System.out.println();
    			}
    		}
    	}
    }
    







  • 相关阅读:
    OK335xS-Android mkmmc-android-ubifs.sh hacking
    OK335xS-Android pack-ubi-256M.sh hacking
    OK335xS Ubuntu 12.04.1 版本 Android 开发环境搭建
    Qt Quick Hello World hacking
    Qt QML referenceexamples attached Demo hacking
    QT 5.4.1 for Android Ubuntu QtWebView Demo
    I.MX6 working note for high efficiency
    QT 5.4.1 for Android Windows环境搭建
    mkbootimg hacking
    Generate And Play A Tone In Android hacking
  • 原文地址:https://www.cnblogs.com/webmen/p/5739223.html
Copyright © 2011-2022 走看看