valeriikozlov
4680 / 2506 / 322
Регистрация: 18.08.2009
Сообщений: 4,550
|
04.12.2010, 08:19
|
|
Вариант быстрее:
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
| #include <iostream>
#include <iomanip>
#include <time.h>
using namespace std;
int func(int last)
{
int mas[10]={0}, col=0, temp=0, i, temp1;
while(last>0)
{
if(last>0 && last<10)
temp1=last;
mas[last%10]++;
last/=10;
col++;
}
while(col>0)
{
if(temp==0)
{
if(temp1==9)
{
for(i=1; i<10; i++)
if(mas[i]==0)
{
temp=i;
break;
}
}
else
{
for(i=1; i<10; i++)
if(mas[i]==0 && i>temp1)
{
temp=i;
col--;
break;
}
}
}
else
{
for(i=0; i<10; i++)
if(mas[i]==0)
{
while(col>0)
{
temp*=10; temp+=i; col--;
}
break;
}
}
}
return temp;
}
int main()
{
srand(static_cast<unsigned int>(time(0)));
int N = 49;
int last_num = 1; cout << last_num << " "<<0<<" ";
for (int i=0; i<N; i++)
{
cout << last_num << " ";
int next_num = func(last_num);
last_num = next_num;
}
system("pause");
return 0;
} |
|
2
|