gpt4 book ai didi

C# 算法代码未通过测试用例

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:40:46 24 4
gpt4 key购买 nike

挑战是根据给定的输入计算一顿饭的总费用:

  1. 餐费(不含税或小费)(双倍)
  2. 小费百分比(以整数形式给出)
  3. 税收百分比(以整数形式给出)

NOTE: These data types by default must remain this way. I cannot change their initial declaration to be double instead of int

给定的步骤如下:

  1. 读取 3 个值的输入
  2. 使用 tip = mealCost x (tipPercent/100) 计算小费
  3. 使用 tax = mealCost x (taxPercent/100) 计算税金
  4. 通过添加 mealCosttiptax 来计算总餐费。
  5. 将最终答案四舍五入并打印出来(如“总餐费为 totalCost 美元。”)

所以我的程序是这样进行的:

using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;

class Solution {

// Complete the solve function below.
static void solve(double meal_cost, int tip_percent, int tax_percent) {
double tip = meal_cost * (tip_percent / 100.0);
double tax = meal_cost * (tax_percent / 100.0);

double totalCost = (meal_cost + tip + tax);

Console.WriteLine("The total meal cost is {0} dollars", Convert.ToInt32(totalCost));
}

static void Main(string[] args) {
double meal_cost = Convert.ToDouble(Console.ReadLine());

int tip_percent = Convert.ToInt32(Console.ReadLine());

int tax_percent = Convert.ToInt32(Console.ReadLine());

solve(meal_cost, tip_percent, tax_percent);
}
}

然而,尽管我的输出是相同的(甚至在四舍五入之前),HackerRank 仍然将我的解决方案识别为“失败”的测试用例,而不是我的自定义测试用例。对此有什么解释吗?

NOTE: The formula provided by HackerRank is actually (Meal Cost) x Tax Percent / 100. I just wrote down the implementation

最佳答案

你打错了一个小字。当您应该使用 dollars. 时,您使用了 dollars

对您的代码进行更改后,它会在 https://www.hackerrank.com/challenges/30-operators/problem 处通过.

关于C# 算法代码未通过测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51316562/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com