【问题标题】:Algorithm calculate score算法计算分数
【发布时间】:2016-11-21 13:43:24
【问题描述】:

我有一个像图片一样的乐谱和A、B、C、D、E的5个部分

A 部分,我有 10 分匹配 1 颗星。 B 部分,我有 20 分与 2 星匹配,C 部分与 40 分与 3 星匹配......当我获得 3 颗星时,我有 70 分。我需要帮助,当我有分数时,我需要调整白条的大小以与我的分数匹配,有什么帮助吗?

【问题讨论】:

  • 定义范围能解决您的问题吗?
  • 我的规则:1星-10分、2星-30分、3星-70分、4星-150分、5星-310分。分数栏是 600 宽,我可以根据分数调整大小匹配

标签: algorithm


【解决方案1】:
final int barSize = 600;
double barPercent;
double score = getScore();
// Assumed every section is 20% of barPercent
if (score >= 0 && score <= 10){
    barPercent = score / 10 * 20;
}else if (score > 10 && score <= 30){
    barPercent = 20 + (score - 10) / 20 * 20;
}else if (score > 30 && score <= 70){
    barPercent = 40 + (score - 30) / 40 * 20;
}else {...}

int result = barSize * barPercent / 100;
return result;

// test case:
// 50 score => bar=50 => result=300

希望对你有帮助

【讨论】:

  • 我的进度条是 600 宽度,如果我有 50 分,我需要将进度条调整到 C 部分的中心,意思是我的进度条调整到 300 宽度
  • 更新并添加了一个测试用例。
  • 谢谢,它有效:)。我认为替换: int result = barSize * barPercent; with int result = barSize * (barPercent/100);
猜你喜欢
  • 2017-01-24
  • 1970-01-01
  • 2020-01-30
  • 2017-08-12
  • 2021-03-22
  • 1970-01-01
  • 2011-04-13
  • 2020-10-07
  • 1970-01-01
相关资源
最近更新 更多