题目是这样的:
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
This is a simple question.
Given you two hexadecimal digits x and y, you
should determine whether 2x+10 is greater than 3y+5.
输入描述:
Each test contain multiple test cases. The first line contains
the number of test cases t (1≤t≤100). Description of the test cases follow.
The description of each test case consists of two
hexadecimal digits x, y separated by spaces.
It's guarantee that x ,y only consists of number '0'-'9'
and capital letters 'A'-'F' and there are no leading zeros.
1≤x,y<16^1000
输出描述:
For each test case, if 2x+10 > 3y+5, print "Yes",
Otherwise print "No".
示例1
输入
3
A B
F0 E11
FF0123FFFFFFFFFF 01FEA23FFF
输出
No
No
Yes
我的代码是这样的:
#include<stdio.h>
#include<string.h>
int turn(char a, int t)
{
if (a == 'A' || a == 'a') return 10 * t;
else if (a == 'B' || a == 'b') return 11 * t;
else if (a == 'C' || a == 'c') return 12 * t;
else if (a == 'D' || a == 'd') return 13 * t;
else if (a == 'E' || a == 'e') return 14 * t;
else if (a == 'F' || a == 'f') return 15 * t;
else return (a - '0') * t;
}
char retu(int t)
{
if (t >= 0 && t <= 9) return t + '0';
else if (t == 10) return 'A';
else if (t == 11) return 'B';
else if (t == 12) return 'C';
else if (t == 13) return 'D';
else if (t == 14) return 'E';
else return 'F';
}
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
char a[1005] = { 0 }, b[1005] = { 0 };
char ta[1005] = { 0 }, tb[1005] = { 0 };
scanf("%s %s", a, b);
int loa = strlen(a);
int lob = strlen(b);
int ia[1005] = { 0 }, ib[1005] = { 0 };
for (int i = 0; i <= loa; i++)//处理x
{
if(i < loa)
ia[i] += turn(a[i], 2);
if (i == 0)
ia[i] += 10;//转成运算后的数字
while (ia[i] >= 16)//判断进位
{
ia[i] -= 16;
ia[i + 1] += 1;
}
if(i < loa || i == loa && ia[i] != 0)//防止前导0出现影响长度
ta[i] = retu(ia[i]);
}
for (int i = 0; i <= lob; i++)//处理y
{
if(i < lob)
ib[i] += turn(b[i], 3);//同x
if (i == 0)
ib[i] += 5;
while (ib[i] >= 16)
{
ib[i] -= 16;
ib[i + 1] += 1;
}
if(i < lob || i == lob && ib[i] != 0)
tb[i] = retu(ib[i]);
}
int lowa = strlen(ta), lowb = strlen(tb);
if (lowa > lowb)//长度大的必然大
printf("Yes\n");
else if (lowa < lowb)
printf("No\n");
else
{
int u;
for (u = lowa - 1; u >= 0; u--)//由于存的时候是从位置0开始存的,所以位置0是最小位,应从最后一位开始比
{
if (ta[u] > tb[u])
{
printf("Yes\n");
break;
}
else if(ta[u] < tb[u])
{
printf("No\n");
break;
}
else continue;
}
if (u == -1)//相等的情况
printf("No\n");
}
}
}
没有通过所有测试样例
求解