`
java-mans
  • 浏览: 11741565 次
文章分类
社区版块
存档分类
最新评论

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");
	}
}


分享到:
评论

相关推荐

    奥数英语题单词归纳.docx

    - consecutive number(连续整数):相邻的两个整数。 - real number/rational number(实数,有理数):可以写成两个整数比例的数,包含有理数和无理数。 - irrational number(无理数):不能表示为两个整数...

    C++出错提示英汉对照表

    Illegal octal digit ------------------非法的8进制数字 houjiuming Illegal pointer subtraction ------------------非法的指针相减 Illegal structure operation ------------------非法的结构体操作 Illegal ...

    LeetCode最全代码

    260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [C++](./C++/single-number-iii.cpp) [Python](./Python/single-number-iii.py) | _O(n)_ | _O(1)_ | Medium || 268| [Missing ...

    数学专业英语常用词汇.doc

    - `consecutive number` 是连续整数。 - `real number` 或 `rational number` 是实数,`irrational number` 是无理数。 - `inverse` 是倒数,`composite number` 是合数,如 4, 6, 8, 9, 10, 12, 14, 15 等。 - ...

    高中数学词汇英文.doc

    - 连续整数(consecutive number):相邻的整数。 - 实数(real number, rational number):所有有理数和无理数的总称。 - 无理数(irrational number):不能表示为两个整数比例的数。 - 倒数(inverse):两...

    数学术语英文对照.docx

    在数论部分,包括natural number、positive number、negative number、odd integer、even integer、integer、whole number、positive whole number、negative whole number、consecutive number、real number、...

    英语科技论文中的数学词汇

    - **Consecutive Number** (连续整数): 相邻的整数。 - **Real Number**, **Rational Number** (实数/有理数): 可以表示为两个整数比的数。 - **Irrational (Number)** (无理数): 不能表示为两个整数比的数。 - **...

    备战ACT考试必刷单词详细汇总之代数词汇.docx

    - **连续整数** (consecutive integer):连续的整数序列。 - **实数** (real number):包括有理数和无理数的集合。 - **复数** (complex number):包含实部和虚部的数,如a + bi。 - **有理数** (rational ...

    GRE数学词汇大汇总(全!!).pdf

    奇数是"odd integer, odd number",偶数是"even integer, even number",整数是"integer, whole number",正整数是"positive whole number",负整数是"negative whole number",连续整数是"consecutive number"。...

    数学相关英语词汇.doc

    25. **Most/least significant digit** (最高/低位, 最高/低有效位数字): 数字中最重要或最不重要的数字。 26. **Nearest** (最近的): 与某个数值最接近的值。 27. **Order** (序、次序): 数字的排列方式。 28. **...

    pat甲级单词pat甲级单词pat甲级单词

    **连续的(Consecutive)** - **定义**: 接连不断地发生。 - **用途**: 在处理序列数据时用于表示元素之间的连续性。 #### 35. **常数(Constant)** - **定义**: 在程序执行过程中不会改变的量。 - **用途**: 在算法...

    数位板压力测试

    sdk LCS/Telegraphics Wintab* Interface Specification 1.1: 16- and 32-bit API Reference By Rick Poyner Revised February 11, 2012 This specification was developed in response to a perceived need for a...

Global site tag (gtag.js) - Google Analytics