Missing Numbers

链接:https://ac.nowcoder.com/acm/contest/13168/D
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld
题目描述
You enjoy your new job as a teacher of young children. It’s fun to see them learning to count, recognize letters, draw, and interact with the world.

One common problem you’ve noticed is that children often forget numbers when counting. For example, early on they might count “one, two, three, five, six.” You have to remind them about that “four” that they didn’t say. And as they get more proficient and clever, they may use the “quick” way of counting: “one, two, skip a few, ninety-nine, one hundred!”

Please write a program that can help you (and your students) identify the missing numbers when they are counting.
输入描述:
The first line of input contains a single integer nn, where 1 \leq n \leq 1001≤n≤100. Each of the next nn lines contains one number that the child recited. Each recited number is an integer between 11 and 200200 (inclusive). They are listed in increasing order, and there are no duplicates.
输出描述:
If the child recited all the numbers between 11 and the last number they recited, then print good ~jobgood job.

If the child missed any numbers between 11 and the last number they recited, then print those missing numbers in increasing numeric order, one per line.

示例1
输入

9
2
4
5
7
8
9
10
11
13

输出

1
3
6
12

示例2
输入

5
1
2
3
4
5

输出

good job

解题思路

关键:贪心算法
输入的过程中记录最大的数字,同时不断地记录出现过的数值;
从 1-max 中查找未出现过的数值,num 来记录个数,同时输出

#include<iostream>
using namespace std;

int main()
{
	int n;
	cin>>n;
	
	int a[201]={0},x,max=0;
	while(n--){
		cin>>x;
		a[x]++;
		if(max<x)	max=x;
	}
	
	int num=0;
	for(int i=1;i<=max;i++){
		if(!a[i]){
			cout<<i<<endl;
			num++;
		}
	}
	
	if(!num)
		cout<<"good job"<<endl;
	return 0;
 } 

没明白的话,欢迎来打扰;
学会了的话,留下一个赞,互相鼓励哦!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值