NOJ [1295] About Loop

来源:互联网 发布:风险矩阵法判断准则 编辑:程序博客网 时间:2024/06/06 13:57
  • 问题描述
  • 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;
    }





0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 卫生间窗在厨房怎么办 联想保修期过了怎么办 s8背面碎了怎么办 三星c5玩游戏卡怎么办 三星关机键失灵怎么办 购机凭证丢了怎么办 滴滴没人接单怎么办 头发干怎么办才好 唯品会东西碎了怎么办 唯品会买东西有质量问题怎么办 来分期不能退货怎么办 商场不肯退衣服怎么办 唯品会衣服坏了怎么办 京东买电视拆机坏的怎么办 余额宝资金冻结怎么办? 余额宝金额冻结怎么办 adidas买了假货怎么办 余额宝冻结金额怎么办 买到不合格地板怎么办 买到翻新地板怎么办 食品里有头发怎么办 家具环保不达标怎么办 买到坏了的食物怎么办 空调检测不合格的怎么办 淘宝卖精仿遇到打假怎么办? 没有收到提货码怎么办 增值税发票超过180天怎么办 花呗借钱还不上怎么办 实体店里没人气怎么办 EMS快件无人签收怎么办 邮政快递丢失了怎么办 快递手机丢了怎么办 拍照签收没收到怎么办 拼多多开店货源怎么办 被购买鉴定投诉怎么办 淘宝上买东西错想用花呗怎么办 淘宝想用花呗买东西差一点怎么办 买了假货怎么办还用吗 免税店买完东西怎么办 淘宝恶意拍单怎么办 二手西服不想要怎么办