亦行之 2024-03-22 20:09 采纳率: 34.5%
浏览 2

pat龟兔赛跑无法得到正确答案

img


以下是我的代码:

#include<stdio.h>
int main()
{
    int x;
    scanf("%d",&x);
    int g=0,t=0,time=0;//跑的距离
    while(time<x){
        time++;//
        g+=3;
        t+=9;
        if(time%10==0){
            if(t>g){
                time+=30;
                g+=30*3;
            }
        /*    else{
                time+=10;
                t+=10*9;
                g+=10*3;
            }    */
        }
    } 
    if(g>t){
        printf("@_@ %d",g);
    }else if(g==t){
        printf("-_-");
    }else{
        printf("^_^ %d",t);
    }
    return 0;
}

请问为什么我的输出结果不正确呢?哪里有问题?

  • 写回答

2条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2024-03-22 22:15
    关注

    【相关推荐】



    • 你可以看下这个问题的回答https://ask.csdn.net/questions/7551547
    • 你也可以参考下这篇文章:PAT C语言 1031 查验身份证 (15 分) 一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算规则如下:
    • 除此之外, 这篇博客: PAT 甲级 英语基础中的 树专题 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:

      PAT-甲-2019-秋-7-3
      a syntax tree (binary) 一个语法树(二进制)
      the corresponding postfix expression 后缀表达式
      with parentheses reflecting the precedences of the operators
      用括号反映运算符的优先顺序。
      symbols. 符号
      corresponds 对应
      PAT-甲-2019-春-7-4
      a binary tree are distinct positive integers 二叉树是不同的正整数
      the postorder and inorder traversal sequences 后序和中序
      on the same level, 同一层
      PAT-甲-2018-冬-7-4
      Heap 堆
      data structure 数据结构
      a heap is a specialized tree-based data 堆是一种特殊的基于树的数据结构
      satisfies the heap property 它满足堆属性
      non-increasing/non-decreasing order. 非递增/非递减的
      the level order traversal sequence of a complete binary tree. 完全二叉树的层序遍历序列。
      occupies a line 占一行
      right subtree 右子树
      PAT-甲-2018-春-7-4
      A common implementation of a heap is the binary heap, in which the tree is a complete binary tree.
      堆的一个常见实现是二进制堆,其中的树是一个完整的二叉树。
      tree’s postorder traversal sequence. 树的后序遍历序列。
      PAT-甲-2018-秋-7-4
      The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as descendants.
      树中两个节点U和V的最低共同祖先(LCA)是同时具有U和V作为后代的最深节点。
      the inorder and preorder traversal sequences of the binary tree 二叉树的序与前序遍历序列


    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

问题事件

  • 创建了问题 3月22日

悬赏问题

  • ¥20 python忆阻器数字识别
  • ¥15 无法输出helloworld
  • ¥15 高通uboot 打印ubi init err 22
  • ¥20 PDF元数据中的XMP媒体管理属性
  • ¥15 R语言中lasso回归报错
  • ¥15 网站突然不能访问了,上午还好好的
  • ¥15 有没有dl可以帮弄”我去图书馆”秒选道具和积分
  • ¥15 semrush,SEO,内嵌网站,api
  • ¥15 Stata:为什么reghdfe后的因变量没有被发现识别啊
  • ¥15 振荡电路,ADS仿真