Division UVa725

That Italy: an input n (2 <= n <= 79)

To find out whether the presence abcde / fghij = n expression

Direct enumeration, for each fghij, judgment abcde, all numbers may not equal (each number appears), but pay attention to enumerate the range, as well as the format, the format is really a headache.

code show as below

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define INF 0x7fffffffffffffff

typedef long long ll;
const double PI=3.1415926535897931;
const long long mod=1e9+7;
const int MA= 1e7+10;
const int ma= 2*1e5+10;
const int few=1e3+10;
const int maxn=1e8+10;
using namespace std;
///////////////////////////////////////////// / 

int the Check ( int a, int B) 
{ 
    int VIS [ 10 ]; 
    Memset (VIS, 0 , the sizeof (VIS)); // record each number appears 
    iF (a> 98765 )
         return  0 ; // ABCDE not be greater than this number 
    String str1, str2; 
    str1 = the to_string (A); 
    str2 = the to_string (B);
     for ( int I = 0 ; I <str1.size (); I ++ ) 
    {
        VIS [str1 [I] - 48 ] = . 1 ; 
    } 
    for ( int I = 0 ; I <str2.size (); I ++ ) 
    { 
        VIS [str2 [I] - 48 ] = . 1 ; 
    } 
    IF (B < 10000 ) 
        VIS [ 0 ] = . 1 ; // . 4 digits, then manually pre-coupled 0 
    int SUM = 0 ;
     for ( int I = 0 ; I < 10 ; I ++ ) 
        SUM + = VIS [I];
    return SUM == 10 ; // check if all numbers appear, i.e., all fghij abcde and numbers are not the same. 
}
 Int main () 
{ 
    int CNT = 0 , n-;
     the while (CIN >> n-&& n-) 
    { 
        IF (CNT ++ ) 
            COUT << endl;
         int In Flag = 0 ;
         for ( int I = 1234 ; I < 99999 ; I ++ ) 
        { 
            IF (Check (n-* I, I)) 
            { 
                the printf ( "% 05d /% 05d =% D \ n- " , I * n-, I, n-); 
                In Flag = . 1 ; 
            } 
        } 
        IF (! In Flag) 
        { 
            the printf ( " There are NO Solutions for% D \ n-. " , N-) ; // boring output format, ah ah ah ah ah ah ah 
        } 
    } 
    return  0 ; 
}

 

Guess you like

Origin www.cnblogs.com/Aracne/p/12387353.html