每日一练-蓝桥杯训练题解-Hello, world!(问题1083)

题目描述
This is the first problem for test. Since all we know the ASCII code, your job is simple: Input numbers and output corresponding messages.
输入
The input will contain a list of positive integers separated by whitespaces(spaces, newlines, TABs). Please process to the end of file (EOF). The integers will be no less than 32.
输出
Output the corresponding message. Note there is NOT a newline character in the end of output.
样例输入
72 101 108 108 111 44
32 119 111 114 108 100 33
样例输出
Hello, world!
解题思路
emmmm,这道题并没有什么难度,只不过对于英语有点菜的我可能有点难受,不过,我们只需要划重点理解就好了,我们从输入那里知道输入包括了这些(spaces, newlines, TABs),所以,注意一下循环的条件就好了(数字要求大于等于32),还有就是,这些,我们直接用char模板做就好了,输入数字,以字符输出时,会自动转换的,在这里我不用数组,毕竟空间会浪费,所以我选择容器中的vector
参考代码

#include<iostream>
#include<stdlib.h>
#include<vector>
#include<stdio.h>
using namespace std;
int main()
{
	vector<char> k;
	int n;
	while (scanf("%d", &n) != EOF && n >= 32) 
	{
		k.emplace_back(n);
	}
	for(int i = 0; i < k.size(); ++i)
	{
		printf("%c", k[i]);
	}


	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42792088/article/details/86633373