#include
<
stdio.h
>
#include
<
stdlib.h
>
#include
<
string
.h
>
int
visite[
15
];
char
str[
100
];
int
d[
100
];
int
len;
bool
multi(
int
n )
{
int
t[
100
];
int
v[
15
];
for
(
int
i
=
0
; i
<
len;
++
i ) t[i]
=
d[i];
for
(
int
i
=
0
; i
<
15
;
++
i ) v[i]
=
visite[i];
for
(
int
i
=
0
; i
<
len;
++
i )
t[i]
*=
n;
for
(
int
i
=
len
-
1
; i
>
0
; i
--
)
{
t[i
-
1
]
+=
t[i]
/
10
;
t[i]
%=
10
;
}
if
( t[
0
]
>=
10
)
return
false
;
for
(
int
i
=
0
; i
<
len;
++
i )
if
(
--
v[ t[i] ]
<
0
)
return
false
;
return
true
;
}
bool
isok()
{
for
(
int
i
=
2
; i
<=
len;
++
i )
if
(
!
multi( i ) )
return
false
;
return
true
;
}
int
main()
{
while
( scanf(
"
%s
"
,str)
!=
EOF )
{
len
=
strlen( str );
memset( visite,
0
,
sizeof
(visite) );
for
(
int
i
=
0
; i
<
len;
++
i ) { d[i]
=
str[i]
-
'
0
'
; visite[ d[i] ]
++
; }
if
( isok() ) printf(
"
%s is cyclic\n
"
, str );
else
printf(
"
%s is not cyclic\n
"
, str );
}
return
0
;
}
posted on 2008-10-30 21:16
Darren 阅读(283)
评论(0) 编辑 收藏 引用 所属分类:
图论