信息学奥赛一本通 1.3:程序的控制结构(1)

第一部分 C++语言

第三章 程序的控制结构

第一节 if选择结构

1039 判断数正负
​#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;

    if (n > 0) {
        cout << "positive" << endl;
    }
    else if (n == 0) {
        cout << "zero" << endl;
    }
    else {
        cout << "negative" << endl;
    }

    return 0;
}
1040 输出绝对值
#include <cstdio>
using namespace std;

int main() {
    float a;
    scanf("%f",&a);

    if (a < 0) {
        printf("%.2f\n", -1 * a);
    }
    else {
        printf("%.2f\n", a);
    }

    return 0;
}
1041 奇偶数判断
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;

    if (n%2 == 0) {
        cout << "even" << endl;
    }
    else {
        cout << "odd" << endl;
    }

    return 0;
}
1042 奇偶ASCII值判断
#include <iostream>
using namespace std;

int main() {
    char c;
    cin >> c;

    if (c%2 == 1) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

    return 0;
}
1043 整数大小比较
#include <iostream>
using namespace std;

int main() {
    int x, y;
    cin >> x >> y;

    if (x > y) {
        cout << '>' << endl;
    }
    else if (x == y) {
        cout << '='<< endl;
    }
    else {
        cout << '<' << endl;
    }

    return 0;
}
1044 判断是否为两位数
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;

    if (n >=10 && n <= 99) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }

    return 0;
}
1045 收集瓶盖赢大奖
#include <iostream>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    if (a>=10 || b >=20) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }

    return 0;
}
1046 判断一个数能否同时被3和5整除
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;

    if (n%3 == 0 && n%5 ==0) {
        cout << "YES" << endl;
}
    else {
        cout << "NO" << endl;
    }

    return 0;
}
1047 判断能否被3,5,7整除
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;

    if (n%3!=0 && n%5!=0 && n%7!=0) {
        cout << 'n' << endl;
    }
    else {
        if (n%3 == 0) {
            cout << "3 ";
        }
        if (n%5 == 0) {
            cout << "5 ";
        }
        if (n%7 == 0) {
            cout << "7 ";
        }
    }

    return 0;
}
1048 有一门课不及格的学生
#include <iostream>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    if ((a>=60) == (b>=60)) {
        cout << 0 << endl;
    }
    else {
        cout << 1 << endl;
    }

    return 0;
}

如果您的孩子四年级及以上,对计算机编程感兴趣,且文化课学有余力,欢迎联系客服(微信号:xiaolan7321),参加信息学的学习。我们是专业的信息学竞赛教练,采用线上小班授课的方式,目标是帮助热爱编程的中小学生,在国内外信息学竞赛中取得优秀成绩。

教学特点:

  • 线上小班授课,打好代码基础。避免大班课堂上学生要么“跟不上”,要么“吃不饱”的问题。

  • 教学经验丰富,熟悉学生的知识结构与学习能力,合理安排进度。

  • 以赛代练,通过考级与比赛,不断提高学生能力。

猜你喜欢

转载自blog.csdn.net/davidliule/article/details/106139478