Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:搞什么东西都不懂 我都找不出我是在哪里错了 明明和答案是一样的嘛In Reply To:搞什么东西都不懂 我都找不出我是在哪里错了 明明和答案是一样的嘛 Posted by:yanical at 2006-07-21 08:56:14 > 气死我了 > 建议别人不要做这一题 java的 源码贴这 有空帮我看看输出哪里有问题 import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int s=sc.nextInt(); int n=sc.nextInt(); while(s!=0&&n!=0) { int element[]=new int[9]; element[8]=0; int i; for(i=7;i>=0;i--) { int total=0; for(int j=7;j>i;j--) { if((j-i)!=0) { total=total+element[j]*(int)Math.pow(10, (j-i)); } } int k=n/(int)(Math.pow(10, i))-total; element[i]=k; } int p=7; while(element[p]==0) p--; for(i=1;i<=(2*s+3);i++) { if(i==1) { printfirst(s,element,i,p); System.out.println(); } else if(i==(s+2)) { printmiddle(s,element,i,p); System.out.println(); } else if(i==(2*s+3)) { printlast(s,element,i,p); } else { printother(s,element,i,p); System.out.println(); } } s=sc.nextInt(); n=sc.nextInt(); if(s!=0&&n!=0) System.out.println("\n"); } } public static void printlast(int s,int element[],int i,int p) { int j; for(j=p;j>=0;j--) { if(element[j]==1||element[j]==4||element[j]==7) pallblank(s); else phang(s); if(j!=0) System.out.print(" "); } } public static void printmiddle(int s,int element[],int i,int p) { int j; for(j=p;j>=0;j--) { if(element[j]==1||element[j]==0||element[j]==7) pallblank(s); else phang(s); if(j!=0) System.out.print(" "); } } public static void printfirst(int s,int element[],int i,int p) { int j; for(j=p;j>=0;j--) { if(element[j]==1||element[j]==4) pallblank(s); else phang(s); if(j!=0) System.out.print(" "); } } public static void printother(int s,int element[],int i,int p) { int tag=0; int j; for(int k=2;k<(s+2);k++) { if(i==k) tag=1; } if(tag==1) { for(j=p;j>=0;j--) { if(element[j]==1||element[j]==2||element[j]==3||element[j]==7) { System.out.print(" "); psomeblank(s); System.out.print("|"); } else if(element[j]==5||element[j]==6) { System.out.print("|"); System.out.print(" "); psomeblank(s); } else { System.out.print("|"); psomeblank(s); System.out.print("|"); } if(j!=0) System.out.print(" "); } } else { for(j=p;j>=0;j--) { if(element[j]==2) { System.out.print("|"); System.out.print(" "); psomeblank(s); } else if(element[j]==6||element[j]==8||element[j]==0) { System.out.print("|"); psomeblank(s); System.out.print("|"); } else { System.out.print(" "); psomeblank(s); System.out.print("|"); } if(j!=0) System.out.print(" "); } } } public static void phang(int s) { System.out.print(" "); for(int i=0;i<s;i++) System.out.print("-"); System.out.print(" "); } public static void psomeblank(int s) { for(int i=0;i<s;i++) System.out.print(" "); } public static void pallblank(int s) { for(int i=0;i<(s+2);i++) System.out.print(" "); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator