Friday, January 5, 2018

UVa problem solution 12527 - Different Digits

problem link:


Discuss: this is simple implementation problem.you can use a bool array to check repeat number.as the range is not so big so you can check every integer individually.

try yourself, before see the code



 #include<bits/stdc++.h>
using namespace std;
int digit(int x)
{
    int i,j,flag=0,r;
    bool ara[11];
    memset(ara,false,10);
    while(x>0)
    {
        r=x%10;
        x/=10;
        if(ara[r])
            return false;
        else
        {
            ara[r]=true;
        }
    }
    return true;
}
int main()
{
    int n,m;
    while(cin >>n>>m)
    {
        int i,j,cnt=0,flag=0;
        for(i=n;i<=m;i++)
        {
              if(digit(i))
                cnt++;
        }
        cout <<cnt<<endl;
    }
    return 0;
}

No comments:

Post a Comment