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

这道题这么做,可以么? (内含WA的代码)

Posted by lololo at 2005-12-26 02:07:53 on Problem 2346
不知道考虑哪儿有问题。 如何改正?
3x !

#include<iostream>
#include<stdlib.h> 
using namespace std;

__int64 A[6];
__int64 flag[50]; 
int ten[7]={1,10,100,1000,10000,100000,1000000}; 

__int64 Power(__int64 a, int n) {
    int i=1; __int64 t = a; 
    for(i=1;i<n;i++)a *= t;
    return a; 
}

int sumdig(int n) {                         //计算各位的数字之和
    int sum = 0;
    while(n) {
        sum += n%10;
        n /= 10; 
    }  
    return sum;   
}     

void setup(int n) {    
    int i,t;
    memset(flag,0,sizeof(flag)); 
    for(i=0;i <= ten[n]-1;i++) {
        t = sumdig(i);
        flag[t]++;                        //遍历0 - 99..9,flag存储对应数字之和出现的次数
    }
    for(i=0;i<50;i++){
        if(flag[i]){
            A[n] += Power(flag[i],n);    //将其n次方         
        }     
    }        
}     

int main() {
    int n,i;
    for(i=1;i<=5;i++)
        setup(i);
    //for(i=1;i<=5;i++)cout<<A[i]<<endl;
    cin>>n;
    cout<<A[n/2]<<endl; 
    system("pause");          
	return 0; 
}

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