现在的位置: 首页 > 综合 > 正文

poj 1047 Round and Round We Go

2012年05月03日 ⁄ 综合 ⁄ 共 684字 ⁄ 字号 评论关闭
//大数相乘!注意最后一位是否有进位! 
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int ans[100];

int main()
{
    string str;
    int input[70], tmp[70];
    int i, j, k, len;
    bool flag1;
    while (cin >> str)
    {
          len = str.length();
          flag1 = false;
          for (i = len-1, j = 0; i >= 0; i--, j++)
          {
              input[j] = str[i] - 48;
              tmp[j] = input[j];
          }
          sort(tmp, tmp+j);
          for (i = 1; i <= len; i++)
          {
              if (flag1)  break;
             memset(ans, 0, sizeof(ans));
            for (j = 0; j < len; j++)
            {
                ans[j] += input[j]*i;
                if (ans[j] >= 10)
                {
                    ans[j+1] += ans[j]/10;
                    ans[j] %= 10;
                }
            }
            if (ans[j] >= 10)
            {
                ans[j+1] += ans[j]/10;
                ans[j] %= 10;
                j++;
            }
            sort(ans, ans+j);
            for (k = 0; k < j; k++)
            {
                if (tmp[k] != ans[k])
                {
                    flag1 = true;
                    break;
                }
            }
            if (flag1)  break;
          }
          if (flag1)
             cout << str << " is not cyclic" << endl;
          else
             cout << str << " is cyclic" << endl;
    }
    system("pause");
}

抱歉!评论已关闭.