zoukankan      html  css  js  c++  java
  • POJ 1426

    B - Find The Multiple
    Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u

    Description

    Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no more than 100 decimal digits.

    Input

    The input file may contain multiple test cases. Each line contains a value of n (1 <= n <= 200). A line containing a zero terminates the input.

    Output

    For each value of n in the input print a line containing the corresponding value of m. The decimal representation of m must not contain more than 100 digits. If there are multiple solutions for a given value of n, any one of them is acceptable.

    Sample Input

    2
    6
    19
    0

    Sample Output

    10
    100100100100100100
    111111111111111111

    这个题又是用暴力做的,感觉自己做题就是在拼智力,真正的算法基本不会,好苦恼,不过一定会加强学习哒~做题的过程和做会一道题的感觉都是很好的。

    把这个代码记录下来主要是想记录一下找只有10组成的数的过程,是模仿二进制进位的过程。

     1 #include<stdio.h>
     2 #include<string.h>
     3 int main()
     4 {
     5     int a[30];
     6     int n,i,m = 1;
     7     long long int s = 1;
     8     scanf("%d",&n);
     9     while(n > 0)
    10     {
    11         while(s % n != 0)
    12         {
    13             for(i = 1;a[i] == 1;i++)
    14                 a[i] = 0;
    15             a[i] = 1;
    16             if(i > m)m = i;
    17             for(s = 0,i = m;i >= 1;i--)
    18             {
    19                 s =s * 10 + a[i]; 
    20             }
    21         }
    22         printf("%lld
    ",s);
    23         scanf("%d",&n);
    24         memset(a,0,30*sizeof(int));
    25         s = 1;
    26         m = 1;
    27     }
    28     return 0;
    29 }
    View Code
     
  • 相关阅读:
    C语言面试题——寻找错误
    C语言的声明解释的在线工具——cdecl
    C语言面试题——指针运算
    const 指针与指向const的指针
    C语言复杂声明解释
    poj1248
    poj1750
    poj1484
    poj1853
    poj1575
  • 原文地址:https://www.cnblogs.com/lwy-kitty/p/3199334.html
Copyright © 2011-2022 走看看