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