Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

AC了,求优化

Posted by speedcell4 at 2011-02-08 16:23:37 on Problem 2876
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator