您的位置:首页 > 其它

hdu(2203)

2016-01-15 00:00 232 查看




ViewCode


//超时了,艾~

1
#include
"
iostream
"

2

using

namespace
std;

3

char
a[
100005
],b[
100005
];

4

int
i,j,k;

5

int
L1,L2;

6

int
sign
=
0
;

7

int
mark
=
0
;

8

int
start
=
0
,end
=
0
;

9

void
Xun_huan()
//
实现一次循环

10

{

11

char
ch
=
a[
0
];

12

for
(
int
q
=
0
;q
<=
L1
-
1
;q
++
)

13
{

14
a[q]
=
a[q
+
1
];

15
}

16
a[L1
-
1
]
=
ch;

17
sign
++
;
//
标记循环次数

18

}

19

void
sub(
int
x,
int
y)

20
{

21

if
(b[x]
==
a[y])

22
{

23
sign
++
;

24

if
(sign
==
L2
&&
b[x]
==
b[L2
-
1
])mark
=
1
;
//
标志着搜索成功

25

else
sub(x
+
1
,y
+
1
);

26
}

27

else

28
{

29
sign
=
0
;

30
k
=
0
;

31
}

32
}

33

34

void
X_Sub()
//
实现对循环序列的搜索

35

{

36

for
(i
=
0
;i
<
L1;i
++
)

37
{

38
k
=
0
;

39

if
(b[k]
==
a[i])

40
{

41

if
(b[k]
==
b[L2
-
1
])mark
=
1
;
//
标记首位是否满足条件

42

if
(mark
==
1
)
break
;

43

else
sub(k
+
1
,i
+
1
);

44
}

45
}

46
}

47

int
main()

48
{

49

while
(scanf(
"
%s%s
"
,a,b)
!=
EOF)

50
{

51
mark
=
0
;

52
L1
=
strlen(a);L2
=
strlen(b);

53
start
=
0
;

54
end
=
0
;

55

if
(L2
>
L1)cout
<<
"
no
"
<<
endl;

56

else

57
{

58

int
flag
=

0
;

59

for
(i
=
0
;i
<
L2;i
++
)

60
{

61

for
(j
=
0
;j
<
L1;j
++
)

62
{

63

if
(b[i]
==
a[j]){flag
++
;
break
;}

64
}

65
}

66

if
(flag
!=
L2)cout
<<
"
no
"
<<
endl;

67

else

68
{

69

int
sign
=
0
;

70

71

for
(
int
p
=
0
;p
<
L1;p
++
)
//
i标记循环次数

72

{

73
Xun_huan();

74
sign
=
0
;

75
X_Sub();

76

if
(mark
==
1
&&
sign
==
L2)
break
;

77
}

78

if
(mark
==
1
)cout
<<
"
yes
"
<<
endl;

79

else
cout
<<
"
no
"
<<
endl;

80
}

81
}

82
}

83

return

0
;

84
}




//两个函数搞定,赞了!

#include
<
stdio.h
>

#include
<
string
.h
>

int
main()
{

char
str[
100000
];

char
str1[
100000
];

char
str2[
200000
];

while
(gets(str)){
gets(str1);

strcpy(str2,str);
//
刚开始要cpy,不能直接cat

strcat(str2,str);

if
(strstr(str2,str1)
!=
NULL){
puts(
"
yes
"
);
}
else
{
puts(
"
no
"
);
}
}

return

0
;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: