zoukankan      html  css  js  c++  java
  • POJ 1047 Round and Round We Go

    https://vjudge.net/problem/POJ-1047

    题意:

    给一个整数,它的长度为n,从1开始一直到n和该整数相乘,判断每次结果是否和原来的整数是循环的。

    思路:

    大整数的乘法。

     1 #include <iostream>  
     2 #include <cstdio>  
     3 #include <cstring>  
     4 #include <algorithm>  
     5 #include <cmath>  
     6 #include<vector>
     7 using namespace std;
     8 
     9 char s[65];
    10 int num[65];
    11 int temp[65];
    12 int n;
    13 
    14 bool cacl(int m)
    15 {
    16     int t = 0;
    17     for (int i = 0; i < n; i++)
    18     {
    19         temp[i] = (num[i] * m + t) % 10;
    20         t = (num[i] * m + t) / 10;
    21     }
    22     if (t>0)  return false;
    23     return true;
    24 }
    25 
    26 bool judge()
    27 {
    28     for (int i = 0; i<n; ++i)
    29     {
    30         int k = 0;
    31         if (temp[i] == num[0])
    32         {
    33              while (k<n &&num[++k] == temp[(i+k) % n]);
    34              if (k == n)   return 1;   
    35         }
    36     }
    37     return 0;
    38 }
    39 
    40 int main()
    41 {
    42     //freopen("D:\txt.txt", "r", stdin);
    43     while (gets(s))
    44     {
    45         memset(num, 0, sizeof(num));
    46         n = strlen(s);
    47         for (int i = n - 1; i >= 0; i--)
    48         {
    49             num[n - 1 - i] = s[i] - '0';
    50         }
    51         bool flag = false;
    52         for (int i = 2; i <= n; i++)
    53         {
    54             if (cacl(i))
    55             {
    56                 if (!judge())
    57                 {
    58                     printf("%s is not cyclic
    ", s);
    59                     flag = true;
    60                     break;
    61                 }
    62             }
    63             else
    64             {
    65                 printf("%s is not cyclic
    ", s);
    66                 flag = true;
    67                 break;
    68             }
    69         }
    70         if (!flag)
    71             printf("%s is cyclic
    ", s);
    72     }
    73     return 0;
    74 }
  • 相关阅读:
    Dynamics CRM9.0更新了Chrome后菜单按钮变形
    质量属性
    机器学习理解
    大道之简的理解
    架构之美理解
    1.13
    1.12
    1.11
    1.10
    Flex 替换输入的字符串
  • 原文地址:https://www.cnblogs.com/zyb993963526/p/6659399.html
Copyright © 2011-2022 走看看