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 != '\n' && c != EOF)
        s[i++] = c;
    s[i] = '\0';

    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;
}
时间: 2025-01-13 12:33:19

UVA10878 Decode the tape的相关文章

UVA之10878 - Decode the tape

[题目] Your boss has just unearthed a roll of old computer tapes. The tapes have holes in them and might contain some sort of useful information. It falls to you to figure out what is written on them. Input The input will contain one tape. Output Outpu

UVA 10878 Decode the tape

终于在UVA上看到一题短的题目,高兴了一下.看完题目以后就懵了.然后就找规律了....... 发现每一行都代表一个字母,然后我就从a开始一个个的对照,把他写出来.然后就发现了某种规律:每行的重要位置都是由'o'和'-'组成的,数一下发现恰好有7个,然后就想到了阿斯克码.果然第一个代表2^6,第二个代表2^5,以此类推--如果是'o'就代表1*2^x,否则就是0,相加以后的值就是字母的阿斯克码. 前两次交居然都RE了... #include<stdio.h> #include<string

小白书训练-Decode the tape

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1819 题意:纸带打孔来保持二进制数,打孔便是1,否者为0.这个带子用ASCII保存了一个字符串,一个模拟.用数组使劲RE和WA,无语了.还是一个一个读入过掉的. 代码: #include <iostream> #include <cstdio> using

UVA 10878-Decode the tape(模拟)

Decode the tape Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description "Machines take me by surprise with great frequency." Alan Turing Your boss has just unearthed a roll of old computer tapes. The

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

Linking code for an enhanced application binary interface (ABI) with decode time instruction optimization

A code sequence made up multiple instructions and specifying an offset from a base address is identified in an object file. The offset from the base address corresponds to an offset location in a memory configured for storing an address of a variable

91. Decode Ways

原题目: A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message containing digits, determine the total number of ways to decode it. For example,Given enc

UnicodeDecodeError: &#39;ascii&#39; codec can&#39;t decode byte 0xe0 in position 0

Windows 7/8/10机器上安装Python 2.7后,下载一些Package包进行setup时总是报错UnicodeDecodeError,如下: File "C:/Python27/lib/mimetypes.py", line 250, in enum_types ctype = ctype.encode(default_encoding) # omit in 3.x! UnicodeDecodeError: 'ascii' codec can't decode byte

Python之encode与decode浅析

 Python之encode与decode浅析 在 python 源代码文件中,如果你有用到非ASCII字符,则需要在文件头部进行字符编码的声明,声明如下: # code: UTF-8 因为python 只检查 #.coding 和编码字符串,为了美观等原因可以如下写法: #-*-coding:utf-8-*- 常见编码介绍: GB2312编码:适用于汉字处理.汉字通信等系统之间的信息交换. GBK编码:是汉字编码标准之一,是在 GB2312-80 标准基础上的内码扩展规范,使用了双字节编码.