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 |
AC了,求优化#include<stdio.h> int n; int pow(int a,int b) { if(b==0) return 1; else return a*pow(a,b-1); } void da(char a[],int n,int k) { for(int i=0;n-i;i++) a[k+i]=' '; } void kan(char a[],int n,int k) { int z=pow(3,n-k),m=pow(3,n); for(int i=z;m+1-i>0;) { da(a,z,i); i+=3*z; } } int main() { char a[999999]; for(int i=0;pow(3,12)-i;i++) a[i]='-'; for(int i=1;12+1-i;i++) kan(a,12,i); while(scanf("%d",&n)!=EOF) { for(int i=0;pow(3,n)-i;i++) printf("%c",a[i]); printf("\n"); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator