NOI / 1.1编程基础之输入输出全题详解(8515字)

目录

01:Hello, World!

02:输出第二个整数

03:对齐输出

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

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

06:空格分隔输出

07:输出浮点数

08:字符三角形

09:字符菱形

10:超级玛丽游戏


01:Hello, World!

总时间限制: 

1000ms

内存限制: 

65536kB

描述

对于大部分编程语言来说,编写一个能够输出“Hello, World!”的程序往往是最基本、最简单的。因此,这个程序常常作为一个初学者接触一门新的编程语言所写的第一个程序,也经常用来测试开发、编译环境是否能够正常工作。

现在你就需要完成这样一个程序。

输入

无。

输出

一行,仅包含一个字符串:“Hello, World!”

样例输入

(无)

样例输出

Hello, World!

提示

使用英文标点符号;逗号后面有一个空格。

#include<stdio.h>
main()
{
printf("Hello, World!");
}

直接使用“cin”或“printf”语句输出。

02:输出第二个整数

总时间限制: 

1000ms

内存限制: 

65536kB

描述

输入三个整数,把第二个输入的整数输出。

输入

只有一行,共三个整数,整数之间由一个空格分隔。整数是32位有符号整数。

输出

只有一行,一个整数,即输入的第二个整数。

样例输入

123 456 789

样例输出

456

来源

习题(2-1)

#include<stdio.h>
main()
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
printf("%d",b);
}

先用“scanf”输入3个int变量,再输出第2个变量。

03:对齐输出

总时间限制: 

1000ms

内存限制: 

65536kB

描述

读入三个整数,按每个整数占8个字符的宽度,右对齐输出它们。

输入

只有一行,包含三个整数,整数之间以一个空格分开。

输出

只有一行,按照格式要求依次输出三个整数,之间以一个空格分开。

样例输入

123456789 0 -1

样例输出

123456789        0       -1

来源

习题(2-6)

#include<stdio.h>
main()
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
printf("%8d %8d %8d",a,b,c);
}

“%8d”可以让长度不满8字节的变量增加长度至8字节。

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

总时间限制: 

1000ms

内存限制: 

65536kB

描述

读入一个单精度浮点数,保留3位小数输出这个浮点数。

输入

只有一行,一个单精度浮点数。

输出

也只有一行,读入的单精度浮点数。

样例输入

12.34521

样例输出

12.345

来源

习题(2-2)

#include<stdio.h>
main()
{
	float a;
	scanf("%f",&a);
	printf("%.3f",a);
}

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

总时间限制: 

1000ms

内存限制: 

65536kB

描述

读入一个双精度浮点数,保留12位小数,输出这个浮点数。

输入

只有一行,一个双精度浮点数。

输出

也只有一行,保留12位小数的浮点数。

样例输入

3.1415926535798932

样例输出

3.141592653580

来源

习题(2-3)

#include<stdio.h>
main()
{
double a;
scanf("%lf",&a);
printf("%.12lf",a);
}

这两题非常简单。

06:空格分隔输出

总时间限制: 

1000ms

内存限制: 

65536kB

描述

读入一个字符,一个整数,一个单精度浮点数,一个双精度浮点数,然后按顺序输出它们,并且要求在他们之间用一个空格分隔。输出浮点数时保留6位小数。

输入

共有四行:
第一行是一个字符;
第二行是一个整数;
第三行是一个单精度浮点数;
第四行是一个双精度浮点数。

输出

输出字符、整数、单精度浮点数和双精度浮点数,之间用空格分隔。

样例输入

a
12
2.3
3.2

样例输出

a 12 2.300000 3.200000

来源

习题(2-4)

#include<stdio.h>
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);
}

输入“%c”时要在后面空格。

07:输出浮点数

总时间限制: 

1000ms

内存限制: 

65536kB

描述

读入一个双精度浮点数,分别按输出格式“%f”,“%f”保留5位小数,“%e”和“%g”的形式输出这个整数,每次在单独一行上输出。

输入

一个双精度浮点数。

输出

输出有四行:
第一行是按“%f”输出的双精度浮点数;
第二行是按“%f”保留5位小数输出的双精度浮点数;
第三行是按“%e”输出的双精度浮点数;
第四行是按“%g”输出的双精度浮点数。

样例输入

12.3456789

样例输出

12.345679
12.34568
1.234568e+001
12.3457

来源

习题(2.5)

#include<stdio.h>
main()
{
	double a;
	scanf("%lf",&a);
	printf("%lf\n%.5lf\n%e\n%g",a,a,a,a);
}

08:字符三角形

总时间限制: 

1000ms

内存限制: 

65536kB

描述

给定一个字符,用它构造一个底边长5个字符,高3个字符的等腰字符三角形。

输入

输入只有一行, 包含一个字符。

输出

该字符构成的等腰三角形,底边长5个字符,高3个字符。

样例输入

*

样例输出

  *
 ***
*****

来源

习题(2-7)

#include<stdio.h>
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);
}

09:字符菱形

总时间限制: 

1000ms

内存限制: 

65536kB

描述

给定一个字符,用它构造一个对角线长5个字符,倾斜放置的菱形。

输入

输入只有一行, 包含一个字符。

输出

该字符构成的菱形。

样例输入

*

样例输出

  *
 ***
*****
 ***
  *
#include<stdio.h>
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);
	printf(" %c%c%c\n",a,a,a);
	printf("  %c\n",a);
}

10:超级玛丽游戏

总时间限制: 

1000ms

内存限制: 

65536kB

描述

超级玛丽是一个非常经典的游戏。请你用字符画的形式输出超级玛丽中的一个场景。

输入

无。

输出

如样例所示。

样例输入

(无)

样例输出

                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###                 ###           ###           ###
                ...........               #...#               #...#         #...#         #...#
               ##*#######                 #.#.#               #.#.#         #.#.#         #.#.#
            ####*******######             #.#.#               #.#.#         #.#.#         #.#.#
           ...#***.****.*###....          #...#               #...#         #...#         #...#
           ....**********##.....           ###                 ###           ###           ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################              ##################################
#...#......#.##...#......#.##...#......#.##------------------#              #...#......#.##------------------#
###########################################------------------#              ###############------------------#
#..#....#....##..#....#....##..#....#....#####################              #..#....#....#####################
##########################################    #----------#                  ##############    #----------#
#.....#......##.....#......##.....#......#    #----------#                  #.....#......#    #----------#
##########################################    #----------#                  ##############    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#                  #.#..#....#..#    #----------#
##########################################    ############                  ##############    ############

提示

必须严格按样例输出,每行的行尾不能有空格。

直接输出“

                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###                 ###           ###           ###
                ...........               #...#               #...#         #...#         #...#
               ##*#######                 #.#.#               #.#.#         #.#.#         #.#.#
            ####*******######             #.#.#               #.#.#         #.#.#         #.#.#
           ...#***.****.*###....          #...#               #...#         #...#         #...#
           ....**********##.....           ###                 ###           ###           ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################              ##################################
#...#......#.##...#......#.##...#......#.##------------------#              #...#......#.##------------------#
###########################################------------------#              ###############------------------#
#..#....#....##..#....#....##..#....#....#####################              #..#....#....#####################
##########################################    #----------#                  ##############    #----------#
#.....#......##.....#......##.....#......#    #----------#                  #.....#......#    #----------#
##########################################    #----------#                  ##############    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#                  #.#..#....#..#    #----------#
##########################################    ############                  ##############    ############

”就行了,注意换行。

制作不易,点赞过3个日更。

哦对了。

我再留一道挑战题:

总时间限制: 

15000ms

内存限制: 

150000kB

描述

The rotation game uses a # shaped board, which can hold 24 pieces of square blocks (see Fig.1). The blocks are marked with symbols 1, 2 and 3, with exactly 8 pieces of each kind.


Initially, the blocks are placed on the board randomly. Your task is to move the blocks so that the eight blocks placed in the center square have the same symbol marked. There is only one type of valid move, which is to rotate one of the four lines, each consisting of seven blocks. That is, six blocks in the line are moved towards the head by one block and the head block is moved to the end of the line. The eight possible moves are marked with capital letters A to H. Figure 1 illustrates two consecutive moves, move A and move C from some initial configuration.

输入

The input consists of no more than 30 test cases. Each test case has only one line that contains 24 numbers, which are the symbols of the blocks in the initial configuration. The rows of blocks are listed from top to bottom. For each row the blocks are listed from left to right. The numbers are separated by spaces. For example, the first test case in the sample input corresponds to the initial configuration in Fig.1. There are no blank lines between cases. There is a line containing a single `0' after the last test case that ends the input.

输出

For each test case, you must output two lines. The first line contains all the moves needed to reach the final configuration. Each move is a letter, ranging from `A' to `H', and there should not be any spaces between the letters in the line. If no moves are needed, output `No moves needed' instead. In the second line, you must output the symbol of the blocks in the center square after these moves. If there are several possible solutions, you must output the one that uses the least number of moves. If there is still more than one possible solution, you must output the solution that is smallest in dictionary order for the letters of the moves. There is no need to output blank lines between cases.

样例输入

1 1 1 1 3 2 3 2 3 1 3 2 2 3 1 2 2 2 3 1 2 1 3 3
1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3
0

样例输出

AC
2
DDHH
2

来源

Shanghai 2004

如果谁做出来了,请留言给我 。

おすすめ

転載: blog.csdn.net/mooczhimahu/article/details/121459582