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 |
为什么输出时用putchar()不会超时而用printf("%c")就会超时#include <stdio.h> #include <math.h> #include <string.h> char a[729][729]; void fill(int x,int y,int n) { if (n==1) a[x][y]='X'; else { int t=(int)pow(3,n-2); fill(x,y,n-1); fill(x,y+2*t,n-1); fill(x+t,y+t,n-1); fill(x+2*t,y,n-1); fill(x+2*t,y+2*t,n-1); } } int main() { memset(a,' ',sizeof(a)); fill(0, 0, 7); int i,j,n; while(1) { scanf("%d", &n); if (n==-1) return 0; int m=(int)pow(3,n-1); for (i=0;i<m;i++) { for(j=0;j<m;j++) putchar(a[i][j]); //改为printf("%c",a[i][j])就会超时 putchar('\n'); } printf("-\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator