C++信息学奥赛一本通-第一部分-基础一-第3章-第1节

发布于:2025-08-09 ⋅ 阅读:(16) ⋅ 点赞:(0)

C++信息学奥赛一本通-第一部分-基础一-第3章-第1节

2051 偶数

#include <iostream>

using namespace std;

int main() {
    int number; cin >> number;
    if (number % 2 == 0) {
        cout << "yes";
    }
}

2052 范围判断

#include <iostream>

using namespace std;

int main() {
    int number; cin >> number;
    if (number > 1 && number < 100) {
        cout << "yes";
    }
}

2053 三个数

sort 是左闭右开 这里事实上是指针

#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int nums[3]; cin >> nums[0] >> nums[1] >> nums[2]; 
    sort(nums, nums + 3);
    cout << nums[2] << " " << nums[1] << " " << nums[0] << endl;
}

2054 适合晨练

#include <iostream>

using namespace std;

int main() {
    int number; cin >> number;
    if (number >= 25 && number < 30) cout << "ok!";
    else cout << "no!";
}

2055 收费

#include <iostream>

using namespace std;

int main() {
    double weight; cin >> weight;
    double result;
    if (weight <= 20.0) result = 1.68 * weight;
    else result = 1.98 * weight;
    printf("%.2f", result);
}

2056 最大的数

#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    double nums[3]; cin >> nums[0] >> nums[1] >> nums[2];
    sort(nums, nums + 3);
    cout << nums[2];
}

1039 判断数正负

#include <iostream>

using namespace std;

int main() {
    long long num; cin >> num;
    if (num > 0) cout << "positive";
    else if (num < 0) cout << "negative";
    else cout << "zero";
}

1040 输出绝对值

#include <iostream>
#include <cmath>

using namespace std;

int main() {
    double num; cin >> num;
    cout << abs(num);
}

1041 奇偶数判断

#include <iostream>

using namespace std;

int main() {
    int number; cin >> number;
    if (number % 2 == 0) cout << "even";
    else cout << "odd";
}

1042 奇偶ASCII值判断

#include <iostream>

using namespace std;

int main() {
    char ch; cin >> ch;
    if ((int)ch % 2 == 0) cout << "NO";
    else cout << "YES";
}

1043 整数大小比较

#include <iostream>

using namespace std;

int main() {
    long long a, b; cin >> a >> b;
    if (a > b) cout << ">";
    else if (a == b) cout << "=";
    else cout << "<";
}

1044 判断是否为两位数

#include <iostream>

using namespace std;

int main() {
    int num; cin >> num;
    if (num >= 10 && num <= 99) cout << "1";
    else cout << "0";
}

1045 收集瓶盖赢大奖

#include <iostream>

using namespace std;

int main() {
    int a, b; cin >> a >> b;
    if (a >= 10 || b >= 20) cout << "1";
    else cout << "0";
}

1046 判断一个数能否同时被3和5整除

#include <iostream>

using namespace std;

int main() {
    int num; cin >> num;
    if (num % 3 == 0 && num % 5 == 0) cout << "YES";
    else cout << "NO";
}

1047 判断能否被3 5 7整除

#include <iostream>

using namespace std;

int main() {
    int num; cin >> num;
    if (num % 3 == 0) cout << "3" << " ";
    if (num % 5 == 0) cout << "5" << " ";
    if (num % 7 == 0) cout << "7" << " ";
    if (num % 3 != 0 && num % 5 != 0 && num % 7 != 0) cout << 'n';
}

1048 有一门课不及格的学生

#include <iostream>

using namespace std;

int main() {
    int a, b; cin >> a >> b;
    if ((a < 60 && b < 60) || (a >= 60 && b >= 60)) cout << "0";
    else cout << "1";
}

网站公告

今日签到

点亮在社区的每一天
去签到