当前位置:   article > 正文

Caddi Programming Contest 2021(AtCoder Beginner Contest 193)-A - Discount-题解_kyocera programming contest 2021(atcoder beginner

kyocera programming contest 2021(atcoder beginner contest 200) a


题目大意

一个商品原价A y e n yen yen 现价B y e n yen yen,问优惠了百分之多少


解题思路

ABC第一题,难度不会过高。
虽有精度问题,但是C++中double就够了。


注意事项

记得(a-b)/a后要×100
问的是百分之多少。


AC代码

C++版

#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
typedef long long ll;

int main()
{
    double a, b;
    cin >> a >> b;
    double c = 100 * (a - b) / a;
    printf("%.10lf\n", c);
    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

Python高精度

import decimal
a, b = input().split(' ')
a = decimal.Decimal(a)
b = decimal.Decimal(b)
c = a - b
d = c / a
d *= 100
print(d)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

Python普通版(3行)

a, b = input().split()
a, b = int(a), int(b)
print(100 * (a - b) / a)
  • 1
  • 2
  • 3

Python精简版(2行)

a, b = map(int, input().split(' '))
print(100 * (a - b) / a)
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/52597?site
推荐阅读
  

闽ICP备14008679号