【NOI OpenJudge】【1.1】编程基础之输入输出

文章目录[x]
  1. 0.1:01:Hello, World!
  2. 0.2:02:输出第二个整数
  3. 0.3:03:对齐输出
  4. 0.4:04:输出保留3位小数的浮点数
  5. 0.5:05:输出保留12位小数的浮点数
  6. 0.6:06:空格分隔输出
  7. 0.7:07:输出浮点数
  8. 0.8:08:字符三角形
  9. 0.9:09:字符菱形
  10. 0.10:10: 超级玛丽游戏

                        
                        
                        在这里插入图片描述

01:Hello, World!

#include
#include
using namespace std;
int main(){
    printf("Hello, World!");
    return 0;
}

02:输出第二个整数

#include
#include
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    printf("%8d %8d %8d",a,b,c);
    return 0;
}

03:对齐输出

#include
#include
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    printf("%8d %8d %8d",a,b,c);
    return 0;
}

04:输出保留3位小数的浮点数

#include
int main(){
    double x;
    scanf("%lf",&x);
    printf("%.3lf\n",x);
    return 0;
}

05:输出保留12位小数的浮点数

#include
int main(){
    double x;
    scanf("%lf",&x);
    printf("%.12lf\n",x);
    return 0;
}

06:空格分隔输出

#include
int main(){
    char a;
    int b;
    float c;
    double d;
    scanf("%c%d%f%lf",&a,&b,&c,&d);
    printf("%c %d %f %lf", a, b, c, d);
    return 0;
}

07:输出浮点数

#include
int main(){
    double x;
    scanf("%lf",&x);
    printf("%lf\n%.5lf\n%e\n%g\n",x,x,x,x);
    return 0;
}

08:字符三角形

#include
int main(){
    int n = 3;
    char ch;
    ch = getchar();
    for(int i = 1; i <= n; i++){
        int e = i*2-1;
        int blank = (5-e)/2;
        for(int j = 1; j <= blank; j++){
            printf(" ");
        }
        for(int j = 1; j <= e; j++){
            printf("%c",ch);
        }
        printf("\n");
    }
    return 0;
}

09:字符菱形

#include
int main(){
    int n = 3;
    char ch;
    ch = getchar();
    for(int i = 1; i <= n; i++){
        int e = i*2-1;
        int blank = (5-e)/2;
        for(int j = 1; j <= blank; j++){
            printf(" ");
        }
        for(int j = 1; j <= e; j++){
            printf("%c",ch);
        }
        printf("\n");
    }
    for(int i = n-1; i >= 1; i--){
        int e = i*2-1;
        int blank = (5-e)/2;
        for(int j = 1; j <= blank; j++){
            printf(" ");
        }
        for(int j = 1; j <= e; j++){
            printf("%c",ch);
        }
        printf("\n");
    }
    return 0;
}

10: 超级玛丽游戏

#include
int main(){
    printf("                ********\n");
    printf("               ************\n");
    printf("               ####....#.\n");
    printf("             #..###.....##....\n");
    printf("             ###.......######              ###                 ###           ###           ###\n");
    printf("                ...........               #...#               #...#         #...#         #...#\n");
    printf("               ##*#######                 #.#.#               #.#.#         #.#.#         #.#.#\n");
    printf("            ####*******######             #.#.#               #.#.#         #.#.#         #.#.#\n");
    printf("           ...#***.****.*###....          #...#               #...#         #...#         #...#\n");
    printf("           ....**********##.....           ###                 ###           ###           ###\n");
    printf("           ....****    *****....\n");
    printf("             ####        ####\n");
    printf("           ######        ######\n");
    printf("##############################################################              ##################################\n");
    printf("#...#......#.##...#......#.##...#......#.##------------------#              #...#......#.##------------------#\n");
    printf("###########################################------------------#              ###############------------------#\n");
    printf("#..#....#....##..#....#....##..#....#....#####################              #..#....#....#####################\n");
    printf("##########################################    #----------#                  ##############    #----------#\n");
    printf("#.....#......##.....#......##.....#......#    #----------#                  #.....#......#    #----------#\n");
    printf("##########################################    #----------#                  ##############    #----------#\n");
    printf("#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#                  #.#..#....#..#    #----------#\n");
    printf("##########################################    ############                  ##############    ############\n");
}
点赞

发表评论

昵称和uid可以选填一个,填邮箱必填(留言回复后将会发邮件给你)
tips:输入uid可以快速获得你的昵称和头像