2009-07-20 20:39:19來源不明

NOIP2007 模擬賽 1.吉祥數

作法:模擬

題目的各位數字的N次是...這樣說的

假使n=123 N=3好了

就是sum=1^3+2^3+3^3;

大致上就是這樣,尚餘的看下面吧

/**********************************************************/

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
 int a,b,c,d,n;
 scanf("%d ",&n);
 char in[8500];
 gets(in);
 int m=strlen(in),appear[256]={0},temp=0;
 for(a=0;a<m;a++)
   {
     if(in[a]<=57&&in[a]>=48)
       temp=temp*10+in[a]-48;
     else {appear[temp]++;temp=0;} 
   }
  if(temp!=0) {appear[temp]++;temp=0;}
 for(a=1;a<=n;a++)
    {
      int s[256]={0};
       for(b=0;b<=255;b++)
            if(appear[b]!=0)
              {
               int c=b;
               int sum=0;
                while(c)
                  {
                    int temp=c%10,nn=c%10;
                    for(d=1;d<=a;d++)
                      temp=temp*nn;
                    /*printf("%d ",temp);*/
                    sum=sum+temp;
                    c=c/10;
                  }
                 /* printf("%d\n",sum);*/
                if(sum<=255)
                s[sum]=1;
              }
       for(b=0;b<=255;b++)
         if(s[b]==1) appear[b]=0;
    }
 for(a=0;a<=255;a++)
   if(appear[a]!=0)
     for(b=0;b<appear[a];b++)
      printf("%d ",a);
   printf("\n");
 return 0;
}