NOJ [1295] About Loop

  • 问题描述
  • This day, Death Moon told a story like that:

    One integer can be represented by a binary. For example:

    And you put the leftest ‘1’ to the rightest, it will be:

    Next loop it will be:

    And then the loop is end.

    So now give you a integer, you should print all of its loop in one line.


  • 输入
  • This problem contains several cases. Each case only contains one integer N (1 <= N <= 10000000000000000000).
  • 输出
  • For each case, you should print its whole loop in one line.


    数太大,所以得用__int64,坑爹的我wa了好久

    按题意
    例如8 

    1000 -> 0001 -> 0010 -> 0100
    也就是每次把最左边的数移到最右边,几位的数就有几个对应的数

    #include<stdio.h>
    #include<string.h>

    int str[200];

    int main()
    {
    __int64 n,m;
    while(~scanf("%I64d",&n))
    {
    m=n;
    int cnt=0,len,s,t;
    while(m!=0)
    {
    cnt++;
    m/=2;
    }
    printf("%I64d", n);
    if(n==1|| n==0)
    printf("\n");
    else
    printf(" ");
    len=cnt-1;
    t=len;
    while(n!=0)
    {
    str[len--]=n%2;
    n/=2;
    }
    s=len+1;
    for(int i=0;i<cnt-1;i++)
    {
    str[t+1]=str[s];
    t++;
    s++;
    __int64 temp=0;
    for(int j=s;j<=t;j++)
    if(str[j])
    {
    __int64 tt=1;
    tt<<=(t-j);
    temp+=tt;
    }
    printf("%I64d",temp );
    if(i==cnt-2)
    printf("\n");
    else
    printf(" ");

    }
    }
    return 0;
    }





你可能感兴趣的:(NOJ [1295] About Loop)