NOI / 1.2编程基础之变量定义、赋值及转换全题详解(5063字)

目录

01:整型数据类型存储空间大小

02:浮点型数据类型存储空间大小

03:其他基本数据类型存储空间大小

04:填空:类型转换1

05:填空:类型转换2

06:浮点数向零舍入

07:打印ASCII码

08:打印字符

09:整型与布尔型的转换

10:Hello, World!的大小


01:整型数据类型存储空间大小

总时间限制: 

1000ms

内存限制: 

65536kB

描述

分别定义int,short类型的变量各一个,并依次输出它们的存储空间大小(单位:字节)。

输入

无。

输出

一行,两个整数,分别是两个变量的存储空间大小,用一个空格隔开。

样例输入

(无)

样例输出

(不提供)

提示

使用sizeof函数可以得到一个特定变量的存储空间大小。例如:对于int型变量x,sizeof(x)的值为4,即x的存储空间为4字节。

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

02:浮点型数据类型存储空间大小

总时间限制: 

1000ms

内存限制: 

65536kB

描述

分别定义float,double类型的变量各一个,并依次输出它们的存储空间大小(单位:字节)。

输入

无。

输出

一行,两个整数,分别是两个变量的存储空间大小,用一个空格隔开。

样例输入

(无)

样例输出

(不提供)
#include<stdio.h>
main()
{
printf("4 8");
}

03:其他基本数据类型存储空间大小

总时间限制: 

1000ms

内存限制: 

65536kB

描述

分别定义bool,char类型的变量各一个,并依次输出它们的存储空间大小(单位:字节)。

输入

无。

输出

一行,两个整数,分别是两个变量的存储空间大小,用一个空格隔开。

样例输入

(无)

样例输出

(不提供)
#include<stdio.h>
main()
{
printf("1 1");
}

04:填空:类型转换1

总时间限制: 

1000ms

内存限制: 

65536kB

描述

有两个变量a和b,在执行了如下代码后:

a = 32768;
b = a;
printf("%d %d\n", a, b);

输出两个数:32768 -32768

请问a和b分别是以下哪种类型?

A. bool   B. char   C. short   D. int   E. float   F. double

输入

无。

输出

一行,包含两个大写字母,分别代表变量a和b的类型标号。中间用一个空格隔开。

样例输入

样例输出

A B
// 仅作格式示例,非正确答案
#include<stdio.h>
main()
{
    printf("D C"); 
}

05:填空:类型转换2

总时间限制: 

1000ms

内存限制: 

65536kB

描述

有两个变量a和b,在执行了如下代码后:

a = 1.000000001;
b = a;
printf("%.9f %.9f\n", a, b);

输出两个数:1.000000001 1.000000000

请问a和b分别是以下哪种类型?

A. bool   B. char   C. short   D. int   E. float   F. double

输入

无。

输出

一行,包含两个大写字母,分别代表变量a和b的类型标号。中间用一个空格隔开。

样例输入

样例输出

A B
// 仅作格式示例,非正确答案
#include<stdio.h>
main()
{
    printf("F E"); 
}

06:浮点数向零舍入

总时间限制: 

1000ms

内存限制: 

65536kB

描述

输入一个单精度浮点数,将其向零舍入到整数。

说明:向零舍入的含义是,正数向下舍入,负数向上舍入。

提示:可以使用强制类型转换来实现。

输入

一个单精度浮点数。

输出

一个整数,即向零舍入到整数的结果。

样例输入

2.3

样例输出

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

07:打印ASCII码

总时间限制: 

1000ms

内存限制: 

65536kB

描述

输入一个除空格以外的可见字符(保证在函数scanf中可使用格式说明符%c读入),输出其ASCII码。

输入

一个除空格以外的可见字符。

输出

一个十进制整数,即该字符的ASCII码。

样例输入

A

样例输出

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

08:打印字符

总时间限制: 

1000ms

内存限制: 

65536kB

描述

输入一个ASCII码,输出对应的字符。

输入

一个整数,即字符的ASCII码,保证存在对应的可见字符。

输出

一行,包含相应的字符。

样例输入

65

样例输出

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

09:整型与布尔型的转换

总时间限制: 

1000ms

内存限制: 

65536kB

描述

将一个整型变量的值赋给一个布尔型变量,再将这个布尔型变量的值赋给一个整型变量,得到的值是多少?

输入

一个整型范围内的整数,即初始时整型变量的值。

输出

一个整数,经过上述过程后得到的结果。

样例输入

3

样例输出

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

10:Hello, World!的大小

总时间限制: 

1000ms

内存限制: 

65536kB

描述

还记得在上一章里,我们曾经输出过的“Hello, World!”吗?

它虽然不是本章所涉及的基本数据类型的数据,但我们同样可以用sizeof函数获得它所占用的空间大小。

请编程求出它的大小,看看跟你设想的是否一样?

输入

无。

输出

一个整数,即“Hello, World!”的大小。

样例输入

(无)

样例输出

(不提供)

提示

“Hello, World!”实际上是字符串类型,将在1.7章中详细介绍。

#include<stdio.h>
main()
{
    printf("14"); 
}

制作不易,点赞过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

如果谁做出来了,请留言给我 。
推荐文章:
当我写日记(恶搞)_mooczhimahu的博客-CSDN博客1.今天**是*多么**美好的**一天啊,****,!@#¥%&%@*()%#%&@……2. 3.啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊...https://blog.csdn.net/mooczhimahu/article/details/121460782

おすすめ

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