Consecutive-digit Number

Consecutive-digit Number

Time Limit:1000MS  Memory Limit:65536K
Total Submit:38 Accepted:13

Description

Recently Ginger found that there are many numbers, digits of whom can be rearranged to a consecutive sequence. For instance, 254310 is a consecutive-digit number, since the digits of it are 2, 5, 4, 3, 1 and 0, which can be rearranged to “0, 1, 2, 3, 4, 5”.
A sequence is consecutive, if it forms a one-ascending digit sequence either consecutively or circularly from 9 to 0. For example, both “1, 2, 3, 4” and “8, 9, 0, 1” are consecutive sequences.
The initial zeros of a given number are of course omitted.

Input

There are several input cases, a single positive integer in a single line for each input case.
Input end with 0.

Output

YES or NO in a single line, if the given number is a consecutive-digit number or not.

Sample Input

1423
7980
21350
2100
0

Sample Output

YES
YES
NO
NO
/*
纠错时,把所有特殊数据找出来,并做好记录,方便下次判断
①处的字符处理,比较不错
*/

#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;

char c;
int num[10];
int main(){
	freopen("e://data.in", "r", stdin);
	//freopen("e://data.out", "w", stdout);
	while(1)
	{
		memset(num, 0, sizeof(num));
		while((c = getchar()) == ' ' || c == '\n')//①
			continue;
		while(c == '0') c = getchar();
		while(c != ' ' && c != '\n')
		{
			num[c - '0'] ++;
			c = getchar();
		}
		int i;
		int flag = 0;
		int min = 0x7fffffff, max = 0;
		for(i = 0; i <= 9; ++ i)
		{
			if(num[i] < min)
				min = num[i];
			if(num[i] > max)
				max = num[i];
		}
		if(max == 0)
			break;
		for(i = 0; i <= 9; ++ i)
		{
			num[i] -= min;
			if(num[i] > 1)
			{
				flag = 1;
				break;
			}
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		flag = 0;
		for(i = 0; i <= 9; ++ i)
		{
			if(num[i] && num[(i + 1) % 10] == 0)
				flag ++;
		}
		if(flag < 2)
			printf("YES\n");
		else
			printf("NO\n");
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值