阿白| 2022-01-02 17:40 采纳率: 91.7%
浏览 37
已结题

(大一题) 不知道错哪了

题目是这样的:

时间限制: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");
        }
    }
}


没有通过所有测试样例

求解

  • 写回答

3条回答 默认 最新

  • -Undefined_ 2022-01-02 18:17
    关注
    char retu(int t)
    {
        if (t >= 0 && t <= 9) return t + '0';
        else
            return 'A'+t-10;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 1月2日
  • 已采纳回答 1月2日
  • 修改了问题 1月2日
  • 修改了问题 1月2日
  • 展开全部

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测