Informatics Olympiad 1.2: Sequence structure programming (1)

​The first part of C++ language

Chapter 2 Sequence Structure Program Design

The first section of operators and expressions

1006 A+B question
#include <cstdio>
using namespace std;

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", a + b);

    return 0;
}

#####1007 Calculate the value of (a+b)×c

#include <cstdio>
using namespace std;

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    printf("%d\n", (a + b) * c);

    return 0;
}
1008 Calculate the value of (a+b)/c
#include <cstdio>
using namespace std;

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    printf("%d\n", (a + b) / c);

    return 0;
}
1009 Division with remainder
#include <cstdio>
using namespace std;

int main() {
    int a, b;
    scanf("%d %d %d", &a, &b);
    printf("%d %d\n", a / b, a % b);

    return 0;
}
1010 Calculate the floating point value of the score
#include <cstdio>
using namespace std;

int main() {
    int a, b;
    scanf("%d %d %d", &a, &b);
    printf("%.9lf\n", 1.0 * a / b);

    return 0;
}

Section 2 Constants and Variables

1011 Mortality rate from influenza A epidemic
#include <cstdio>
using namespace std;

int main() {
    int a, b;
    scanf("%d %d %d", &a, &b);
    printf("%.3lf%%\n", 100.0 * b / a);

    return 0;
}
1012 Calculate the value of a polynomial
#include <cstdio>
using namespace std;

int main() {
    double x, a, b, c, d;
    scanf("%lf %lf %lf %lf %lf", &x, &a, &b, &c, &d);
    printf("%.7lf\n", a*x*x*x + b*x*x + c*x +d);

    return 0;
}
1013 Temperature expression transformation
#include <cstdio>
using namespace std;

int main() {
    double F, C;
    scanf("%lf", &F);
    C = 5 * (F - 32) / 9;
    printf("%.5lf\n", C);

    return 0;
}
1014 Calculations related to circles
#include <cstdio>
using namespace std;

int main() {
    double r, d, l , s;
    const double pi = 3.14159;
    scanf("%lf", &r);
    d = 2 * r;
    l = 2 * pi * r;
    s = pi * r * r;
    printf("%.4lf %.4lf %.4lf\n", d, l, s);

    return 0;
}
1015 Calculate the resistance of parallel resistors
#include <cstdio>
using namespace std;

int main() {
    double r1, r2, R;
    scanf("%lf %lf", &r1, &r2);
    R = 1.0 / (1.0 / r1 + 1.0 / r2);
    printf("%.2lf\n", R);

    return 0;
}

Section 3 Standard Data Type

1016 Integer data type storage space size
#include <iostream>
using namespace std;

int main() {
    int a;
    short b;

    cout << sizeof(a) << ' ' << sizeof(b) << endl;

    return 0;
}
1017 Floating-point data type storage space size
#include <iostream>
using namespace std;

int main() {
    float a;
    double b;

    cout << sizeof(a) << ' ' << sizeof(b) << endl;

    return 0;
}
1018 Storage space size of other data types
#include <iostream>
using namespace std;

int main() {
    bool a;
    char b;

    cout << sizeof(a) << ' ' << sizeof(b) << endl;

    return 0;
}
1019 Floating point number is rounded towards zero
#include <iostream>
using namespace std;

int main() {
    float a;

    cin >> a;
    cout << (int)a << endl;

    return 0;
}
1020 print ASCII code
#include <cstdio>
using namespace std;

int main() {
    char ch;

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

    return 0;
}
1021 print characters
#include <cstdio>
using namespace std;

int main() {
    int a;

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

    return 0;
}
1022 Conversion between integer and boolean
#include <cstdio>
using namespace std;

int main() {
    int a;
    bool b;
    int c;

    scanf("%d", &a);
    b = a;
    c = b;
    printf("%d\n", c);

    return 0;
}
1023 The size of Hello, World!
#include <iostream>
using namespace std;

int main() {
    cout << sizeof("Hello, World!") << endl;

    return 0;
}

If your child is in the fourth grade or above, is interested in computer programming and has spare capacity in cultural lessons, please contact customer service (WeChat ID: xiaolan7321) to participate in informatics learning. We are professional informatics competition coaches. We use online small class teaching methods. The goal is to help primary and middle school students who love programming to achieve excellent results in informatics competitions at home and abroad.

Teaching features:

  • Online small class teaching, lay a good code foundation. Avoid the problem that students in large classes are either "can't keep up" or "not enough to eat".

  • Rich teaching experience, familiar with students' knowledge structure and learning ability, and arrange the schedule reasonably.

  • Practice with competitions, and continuously improve students' abilities through examinations and competitions.

Wechat

Guess you like

Origin blog.csdn.net/davidliule/article/details/106139404