All Your Base 模拟题
来源:互联网 发布:sql 合计函数 编辑:程序博客网 时间:2024/06/05 08:34
2011 ACM ICPC SOUTHCENTRALUSA REGIONAL
PROGRAMMINGCONTEST
Premise: Given a specification for a “base” (well, actually a mixedradix number system), take in pairs of numbers written in our“base”, perform
a specified operation on them and output the result in ourbase.
The Base:A number system where the right-most digit (digit 1) canbe a counting number between 0 and 1,the second right-most digit(digit 2) can
be a counting number between 0 and 2 and, more generally, eachdigit n(as labeled from the right) can have values between 0 and n.After 9,
upper case letters are used,starting with A and going through Z.After the highest digit (which can be 0-Z), no further digits arepossible;any
numbers which go past that digit are invalid. Negative numbersare prefixed with a single “-” sign.
Numbers never have leading zeros, with the exception of zeroitself, which is represented by a single “0”character.
Operations:Addition (+) and subtraction (-): The numbers are addedor subtracted as normal (includingcarrying, borrowing, etc).
Input:
The first line of input is the number (base 10) of operations thatneed to be performed.Each following line will be at most 1000 bytesand will
consist of a variable-radix number, a space, a
single character indicating the operation (+, or -), a space,another variable-radix number, and a
newline (LF).
Either number for any operation (and also the result) may benegative.
Output:
For each operation in the input, a single line of output should beproduced containing either the result(a variable-radix number) orthe string
“Invalid”) (without quotes) followed by a newline (LF).
If either of the input numbers or the resulting number is not validin the number system, or an error is
operation, the result is invalid.
Input Output Notes
3 Number of operations; no output for this line
3 + 5
Invalid
9987654321 + 1
A000000000
-A000000000 - 1
-A000000001
题目大意:
给两个 操作数 以及 一个操作符 输出对应的结果
操作数 要求为 最右边第一位为2进制 最右边第二位为3 进制 一次递增 10用A表示 一直到 Z 进制 即35
代码:
#include
#include
int flag1,flag2,len1,len2;
char s[1010];
int is_valid(char t[],int len,int flag)//检测 输入是否 非法
{
}
void
{