免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1682 | 回复: 0
打印 上一主题 下一主题

Practice-Alien Numbers [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-08-18 22:42 |只看该作者 |倒序浏览
Problem
The decimal numeral system is composed of ten digits, which we represent as "0123456789" (the digits in a system are written from lowest to highest). Imagine you have discovered an alien numeral system composed of some number of digits, which may or may not be the same as those used in decimal. For example, if the alien numeral system were represented as "oF8", then the numbers one through ten would be (F, 8, Fo, FF, F8, 8o, 8F, 88, Foo, FoF). We would like to be able to work with numbers in arbitrary alien systems. More generally, we want to be able to convert an arbitrary number that's written in one alien system into a second alien system.
Input
The first line of input gives the number of cases, N. N test cases follow. Each case is a line formatted as
alien_number source_language target_language
Each language will be represented by a list of its digits, ordered from lowest to highest value. No digit will be repeated in any representation, all digits in the alien number will be present in the source language, and the first digit of the alien number will not be the lowest valued digit of the source language (in other words, the alien numbers have no leading zeroes). Each digit will either be a number 0-9, an uppercase or lowercase letter, or one of the following symbols !"#$%&'()*+,-./:;?@[\]^_`{|}~
Output
For each test case, output one line containing "Case #x: " followed by the alien number translated from the source language to the target language.
Limits
1 ≤ N ≤ 100.
Small dataset
1 ≤ num digits in alien_number ≤ 4,
2 ≤ num digits in source_language ≤ 16,
2 ≤ num digits in target_language ≤ 16.
Large dataset
1 ≤ alien_number (in decimal) ≤ 1000000000,
2 ≤ num digits in source_language ≤ 94,
2 ≤ num digits in target_language ≤ 94.
Sample
Input
Output
4
9 0123456789 oF8
Foo oF8 0123456789
13 0123456789abcdef 01
CODE O!CDE? A?JM!.
import os
fileIn=open('A-large-practice.in','r')
fileOut=open("A-large-practive.out","w")
recordlen=fileIn.readline()
print recordlen
i=0
for i in range(int(recordlen)):
    line=fileIn.readline()
    line=line.split()
    c=line[0]
    source=line[1]
    dest=line[2]
   
    valueOfC=0
    for i in range(len(c)):
        valueOfC=valueOfC*len(source)
        valueOfC=valueOfC+source.find(c)
    print valueOfC
    result=''
    while valueOfC>0:
        t=valueOfC%len(dest)
        result=dest[t]+result
        valueOfC=valueOfC/len(dest)
    fileOut.write("Case #"+str(i+1)+":"+result+'\n')
fileIn.close()
fileOut.close()


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/29089/showart_2031152.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP