AcWing基础语法课第一讲习题

文章介绍了使用C++编程语言进行基本数学运算,如变量定义、输入输出、表达式、顺序语句,涉及算术操作(如加减乘除)、几何形状面积、统计计算(如平均数)、财务应用(如工资和奖金)以及一些实用功能(如油耗和距离计算)。
摘要由CSDN通过智能技术生成

第一讲 变量、输入输出、表达式与顺序语句

1. A + B

#include <iostream>

using namespace std;

int main() {

    double a, b;
    
    cin >> a >> b;
    cout << a + b << endl;

    return 0;
}

608. 差

#include <iostream>

using namespace std;

int main(){

    // 定义四个整型变量
    int a, b, c, d;

    cin >> a >> b >> c >> d;
    int x = a * b - c * d;
    cout << "DIFERENCA = " << x << endl;

    return 0;
}

604. 圆的面积

#include <cstdio>

using namespace std;

int main() {

    double PI =  3.14159;
    double radius;
    scanf("%lf", &radius);
    double A = PI * radius * radius;
    printf("A=%.4lf", A);

    return 0;
}

605. 简单乘积

#include <iostream>

using namespace std;

int main(){

    int a, b;
    cin >> a >> b;
    cout << "PROD = " << a * b << endl;

    return 0;
}

606. 平均数1

#include <cstdio>

using namespace std;

int main() {

    double a, b;
    scanf("%lf%lf", &a, &b);
    printf("MEDIA = %.5lf", (a * 3.5 + b * 7.5) / (3.5 + 7.5));

    return 0;
}

609. 工资

#include <cstdio>

using namespace std;

int main() {

    int number, times;
    double hourSalary;
    scanf("%d %d %lf", &number, &times, &hourSalary);
    printf("NUMBER = %d\nSALARY = U$ %.2lf", number, times * hourSalary);

    return 0;
}

610.工资和奖金

#include <cstdio>
#include <iostream>

using namespace std;

int main() {

    string name;
    double x, y;
    cin >> name;
    cin >> x >> y;
    printf("TOTAL = R$ %.2lf", x + y * 0.15);

    return 0;
}

611. 简单计算

#include <cstdio>

int main() {

    int a1, b1,  a2, b2;
    double c1, c2;
    scanf("%d %d %lf", &a1, &b1, &c1);
    scanf("%d %d %lf", &a2, &b2, &c2);
    printf("VALOR A PAGAR: R$ %.2lf", b1 * c1 + b2 * c2);

    return 0;
}

612. 球的面积

#include <cstdio>

int main() {

    int radius;
    double PI = 3.14159;
    scanf("%d", &radius);
    printf("VOLUME = %.3lf", 4 / 3.0 * PI * radius * radius * radius);

    return 0;
}

613. 面积

#include <cstdio>
#include <iostream>

using namespace std;

int main() {

    double a, b, c;
    double PI = 3.14159;
    cin >> a >> b >> c;
    printf("TRIANGULO: %.3lf\n", a * c / 2);
    printf("CIRCULO: %.3lf\n", PI * c * c);
    printf("TRAPEZIO: %.3lf\n", (a + b) * c / 2);
    printf("QUADRADO: %.3lf\n", b * b);
    printf("RETANGULO: %.3lf \n", a * b);

    return 0;
}

614. 最大值

#include <iostream>

using namespace std;

int main() {

    int a, b, c;
    cin >> a >> b >> c;
    int ab = (a + b + abs(a - b)) / 2;
    int abc = (ab + c + abs(ab - c)) / 2;
    cout << abc << " eh o maior" << endl;

    return 0;
}

615. 油耗

#include <cstdio>

using namespace std;

int main() {

    double a, b;
    scanf("%lf%lf", &a, &b);
    printf("%.3lf km/l", a / b);

    return 0;
}

616. 两点间距离

#include <cstdio>
#include <cmath>

using namespace std;

int main() {

    double x1, x2, y1, y2;
    scanf("%lf%lf", &x1, &y1);
    scanf("%lf%lf", &x2, &y2);
    printf("%.4lf", sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));

    return 0;
}

617. 距离

#include <iostream>

using namespace std;

int main() {

    int l;
    cin >> l;
    cout << 2 * l << " minutos" << endl;

    return 0;
}

618. 燃料油耗

#include <cstdio>
#include <iostream>

using namespace std;

int main() {

    double s, t;
    cin >> s >> t;
    printf("%.3lf", s * t / 12);

    return 0;
}

653. 钞票

#include <cstdio>

using namespace std;

int main() {

    int n;
    scanf("%d", &n);
    printf("%d \n", n);

    printf("%d nota(s) de R$ 100,00\n", n / 100);
    n %= 100;
    printf("%d nota(s) de R$ 50,00\n", n / 50);
    n %= 50;
    printf("%d nota(s) de R$ 20,00\n", n / 20);
    n %= 20;
    printf("%d nota(s) de R$ 10,00 \n", n / 10);
    n %= 10;
    printf("%d nota(s) de R$ 5,00\n", n / 5);
    n %= 5;
    printf("%d nota(s) de R$ 2,00 \n", n / 2);
    n %= 2;
    printf("%d nota(s) de R$ 1,00", n / 1);

    return 0;
}

654. 时间转换

#include <cstdio>

using namespace std;

int main() {

    int times, hours, minutes, seconds;
    scanf("%d", &times);
    hours = times / 3600;
    minutes = times % 3600 / 60;
    seconds = times % 60;
    printf("%d:%d:%d", hours, minutes, seconds);

    return 0;
}

655. 天数转换

#include <cstdio>

int main(){

    int days;
    scanf("%d", &days);
    printf("%d ano(s) \n", days / 365);
    printf("%d mes(es) \n", days % 365 / 30);
    printf("%d dia(s)", days % 365 % 30);

    return 0;
}

656. 钞票和硬币

#include <cstdio>
#include <iostream>

using namespace std;

int main() {

    double money;
    scanf("%lf", &money);
    int f = money * 100;
    cout << "NOTAS:" << endl;
    printf("%d nota(s) de R$ 100.00\n", f / 10000);
    f %= 10000;
    printf("%d nota(s) de R$ 50.00\n", f / 5000);
    f %= 5000;
    printf("%d nota(s) de R$ 20.00\n", f / 2000);
    f %= 2000;
    printf("%d nota(s) de R$ 10.00\n", f / 1000);
    f %= 1000;
    printf("%d nota(s) de R$ 5.00\n", f / 500);
    f %= 500;
    printf("%d nota(s) de R$ 2.00\n", f / 200);
    f %= 200;
    cout << "MOEDAS:" << endl;
    printf("%d moeda(s) de R$ 1.00\n", f / 100);
    f %= 100;
    printf("%d moeda(s) de R$ 0.50\n", f / 50);
    f %= 50;
    printf("%d moeda(s) de R$ 0.25\n", f / 25);
    f %= 25;
    printf("%d moeda(s) de R$ 0.10\n", f / 10);
    f %= 10;
    printf("%d moeda(s) de R$ 0.05\n", f / 5);
    f %= 5;
    printf("%d moeda(s) de R$ 0.01\n", f / 1);

    return 0;

}
  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值