Generator

#include<stdio.h>
int book[10001];
int add[4];
int one[10001];
int two[10001];
void fun(int x){
    int temp=x;
    int y=x;
    int t=0;
    while(x){
        add[t]=x%10;
        t++;
        x=x/10;
    }
    for(int j=0;j<t;j++)
        temp=temp+add[j];
    if(book[temp]==0) {
        one[temp]=y;
        book[temp]++;
    }
    else if(book[temp]==1){
        two[temp]=y;
        book[temp]++;
    }

}
int main(){
    int self=0;
    int dup=0;
    for(int i=1;i<=5000;i++) fun(i);
    printf("Print self numbers
");
    for(int i=1;i<=5000;i++)
        if(book[i]==0){ 
            printf("%d ",i);
            self=self+i;
        }
        else if(book[i]==2)
            dup++;
    printf("
");
    printf("Sum of self numbers : %d

",self);
    printf("duplicate generator numbers

");
    printf("Total duplicate numbers : %d

",dup);
    for(int i=0;i<=200;i++)
        if(book[i]==2)
            printf("%d : %d       %d
",i,one[i],two[i]);
}
原文地址:https://www.cnblogs.com/lvcoding/p/6628656.html