zoukankan      html  css  js  c++  java
  • UVA10878 Decode the tape

    阿兰·图林说:“机器的高频率令我震惊。”

    最早的时候,计算机的数据及程序记录卡片上,后来出现了纸带。

    问题链接UVA10878 Decode the tape

    题意简述:本题的题目是纸带编码。输入输入模仿过去的纸带,其中的"|"纸带里是没有的。纸带上信息有7位,通过穿孔实现,有孔的为1(用"o"表示),没孔的地方为0(用空格表示)。中间有一串空用于机械带动纸带,用"."表示。

    问题分析:用输入数据模拟纸带数据。输入的数据放入输入缓冲区中,通常最左边的下标为0。而阿拉伯记数法中,低位在右,高位在左,纸带上的二进制数据也是如此。

    程序说明封装了函数mygets()用于代替库函数gets()(新标准中剔除了该函数)。程序中,根据位权从小到大进行处理,即从右到左(第9位-第1位),位权也逐步增大,需要跳过第6个字符(".")。

    AC的C语言程序如下:

    /* UVA10878 Decode the tape */
    
    #include <stdio.h>
    
    #define MAXN 16
    
    int mygets(char s[])
    {
        int i = 0;
        char c;
    
        while((c = getchar()) && c != '
    ' && c != EOF)
            s[i++] = c;
        s[i] = '';
    
        return i;
    }
    
    int main(void)
    {
        int code, base, i;
        char s[MAXN];
    
        while(mygets(s)) {
            if(s[0] == '_')
                continue;
    
            code = 0;
            base = 1;
    
            for(i=9; i>=1; i--) {
                if(s[i] == 'o')
                    code = code + base;
                if(i != 6)
                    base <<= 1;
            }
    
            printf("%c", code);
        }
    
        return 0;
    }


  • 相关阅读:
    POJ 2411 Mondriaan's Dream
    POJ 2505 A multiplication game
    HDOJ(HDU) 3949 XOR
    雅礼集训DAY 6 T1 xmasdag
    bzoj 2159: Crash 的文明世界
    如何查看Ubuntu版本
    Ubuntu如何安装谷歌Chrome浏览器
    使用nano编辑器进行查找和替换
    Ubuntu修改用户和root密码
    Anaconda/Conda创建环境时报错的解决方案
  • 原文地址:https://www.cnblogs.com/tigerisland/p/7564365.html
Copyright © 2011-2022 走看看