1.除法(Division, UVa 725)

#include <cstdio>
#include <cstring>
bool isOk(int a, int b){
    char buff[20];
    int visited[15];
    memset(visited, 0, sizeof(visited));
    sprintf(buff, "%05d%05d", a, b);
    for (int i =0; i < 10; i++){
        int temp = buff[i] - '0';
        if (0 == visited[temp]){
            visited[temp]++;
        } else {
            return false;
        }
    }
    return true;
}
int main(void){
    int N, cnt = 0;
    bool flag = false;
    for (;scanf("%d", &N) && N;){
        if (cnt > 0){
            printf("\n");
        }
        cnt++;
        flag = false;
        for (int i = 1234; i< 100000; i++){
            if (0 == i%N){
                int ans = i/N;
                if (isOk(i, ans)){
                    printf("%05d / %05d = %d\n", i, ans, N);
                    flag = true;
                } 
            }
        }
        if (!flag){
             printf("There are no solutions for %d.\n",N);
        }        
    }
    return 0;
}
View Code

相关文章:

  • 2022-01-17
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
  • 2022-01-25
  • 2022-02-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
  • 2021-05-28
  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
相关资源
相似解决方案