信息学奥赛一本通 第一章 C++语言入门 C语言非C++

第一章 C++语言入门

1000:入门测试题目

#include <stdio.h>

int main() {
    
    
    // 声明两个整数变量
    int x, y;

    // 从输入读取两个值并赋给x和y
    scanf("%d %d", &x, &y);

    // 计算并打印 (4*x-y)/2 和 (y-2*x)/2 的结果
    printf("%d %d\n", (4*x-y)/2, (y-2*x)/2);

    // main函数结束,返回0表示程序正常执行完毕
    return 0;
}

2060:【例1.1】计算机输出

#include<stdio.h>

int main()
{
    
    
    printf("Hello World!");
    return 0;
}

2061:【例1.2】梯形面积

#include<stdio.h>

int main()
{
    
    
    double h = 150 * 2 / 15.0; // 求高
    printf("%.2f", (15 + 25) * h / 2); // (上底 + 下底) * 高 / 2
    return 0;
}

2062:【例1.3】电影票

#include<stdio.h>

int main()
{
    
    
    int x;
    scanf("%d", &x);
    printf("%d %d", x, 10 * x);
    return 0;
}

2063:【例1.4】牛吃牧草

#include<stdio.h>

int main()
{
    
    
    printf("%d", (15 * 20 - 20 * 10) / (20 - 10));
    return 0;
}

1001:Hello,World!

#include <stdio.h>

int main()
{
    
    
    
    printf("Hello,World!");
    return 0;
}

1002:输出第二个整数

#include <stdio.h>

int main()
{
    
    
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    printf("%d", b);
    return 0;
}

1003:对齐输出

#include <stdio.h> // 引入标准输入输出头文件

int main()
{
    
    
    int a, b, c;  // 声明三个整数变量

    // 从用户输入获取三个整数,并分别赋值给a,b和c
    scanf("%d%d%d", &a, &b, &c);

    // 将三个整数以8个字符宽的字段打印出来,右对齐
    printf("%8d %8d %8d", a, b, c);

    // 程序正常结束,返回0
    return 0;
}

1004:字符三角形

#include <stdio.h>

int main()
{
    
    
    char a;
    scanf(" %c", &a);
    printf("  %c\n", a);
    printf(" %c%c%c\n", a, a, a);
    printf("%c%c%c%c%c\n", a, a, a, a, a);
    return 0;
}

1005:地球人口承载力估计

#include <stdio.h>

int main()
{
    
    
    double x, y, a, b;
    scanf("%lf%lf%lf%lf", &x, &a, &y, &b);
    printf("%.2f", (x * a - y * b) / (a - b));
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44738632/article/details/134974123