int
GetMaxCountofContinuousLetter(
char
*
p,
char
searchChar)

{
int
maxCount
=
0
;
int
currentCount
=
0
;
while
(
1
)

{
if
(
*
p
==
searchChar)

{
currentCount
=
0
;
while
(
*
p
&&
*
p
==
searchChar)

{
currentCount
++
;
p
++
;
}
if
(maxCount
<
currentCount)
maxCount
=
currentCount;
}
if
(
*
p
==
'
\0
'
)
break
;
else
p
++
;
}
return
maxCount;
}
int
main()

{
char
*
p[
3
]
=
{
"
String(1)8818882348888856788888888988888888880
"
,
"
String(2)881888234888885678888888898888888880
"
,
"
String(3)8818882348888856788888888988888888888888880
"
}
;
int
location
=
0
;
char
searchChar
=
'
8
'
;
int
tempCount
=
0
;
int
maxCount
=
0
;
for
(
int
i
=
0
;i
<
sizeof
(p)
/
sizeof
(
*
p);i
++
)

{
tempCount
=
GetMaxCountofContinuousLetter(p[i],searchChar);
if
( tempCount
>
maxCount)

{
maxCount
=
tempCount;
location
=
i;
}
}
cout
<<
"
the string of maxCount is :
"
<<
p[location]
<<
endl;
cout
<<
"
the count of the continuous letters is :
"
<<
maxCount
<<
endl;
cin.
get
();
}
/**/
/*
****************************************
*/
/**/
/*
从str中删除remove中含有的字符
*/
/**/
/*
****************************************
*/
void
RemoveChar(
char
str[],
char
remove[])

{
int
dst,src;
char
removeArray[
256
];
puts(str);
puts(remove);
for
(src
=
0
;src
<
256
;src
++
)

{
removeArray[src]
=
0
;
}
src
=
0
;
while
(remove[src])

{
removeArray[remove[src
++
]]
=
1
;
}
src
=
0
;dst
=
0
;
while
(str[src])

{
if
(
!
removeArray[str[src]])

{
str[dst
++
]
=
str[src];
}
src
++
;
}
str[dst]
=
0
;
puts(str);
}
jeccy (燕飞月天) 于 2006年10月28日21:37:09 星期六 提到:
我的理解,给定2维数组
1 2 3三角形判断
8 9 4
7 6 5
“螺旋式”顺序输出:1 2 3 4 5 6 7 8 9
【 在 bluexyz (数据结构是根本) 的大作中提到: 】
private
static
void
PrintNumberasSpiralOrder()

{
//
1 2 3 4
//
12 13 14 5
//
11 16 15 6
//
10 9 8 7
//
1, 2 , 3, 4, 5
//
16, 17, 18, 19, 6
//
15, 24, 25, 20, 7
//
14, 23, 22, 21, 8
//
13, 12, 11, 10, 9
int
[,] a
=
new
int
[,]

{
{
1
,
2
,
3
,
4
,
5
}
,

{
16
,
17
,
18
,
19
,
6
}
,

{
15
,
24
,
25
,
20
,
7
}
,

{
14
,
23
,
22
,
21
,
8
}
,

{
13
,
12
,
11
,
10
,
9
}
}
;
//
int[,] a = new int[,] { { 1, 2, 3, 4 }, { 12, 13, 14, 5 }, { 11, 16, 15, 6 }, { 10, 9, 8, 7 } };
//
int[,] a = new int[,] { { 1, 2 }, {4,3} };
const
int
N
=
5
;
//
spiral
for
(
int
i
=
N
-
1
, j
=
0
; i
>
0
; i
--
, j
++
)

{
//
i 从最大维度数开始
//
j 从最小维度数开始
//
i--来缩小范围
//
j++来缩小范围
//
k 增长缩小因子
for
(
int
k
=
j; k
<
i; k
++
)
System.Console.Write(
"
{0}
"
, a[j, k]); Console.WriteLine(
""
);
for
(
int
k
=
j; k
<
i; k
++
)
System.Console.Write(
"
{0}
"
, a[k, i]); Console.WriteLine(
""
);
for
(
int
k
=
i; k
>
j; k
--
)
System.Console.Write(
"
{0}
"
, a[i, k]); Console.WriteLine(
""
);
for
(
int
k
=
i; k
>
j; k
--
)
System.Console.Write(
"
{0}
"
, a[k, j]); Console.WriteLine(
""
);
}
//
special case for middle element if N is odd
//
如果是奇数,则要条印中间的数。
if
(N
%
2
==
1
) System.Console.Write(a[(N
-
1
)
/
2
, (N
-
1
)
/
2
]);
}
Reference :
http://bigtiger2005.spaces.live.com/blog/cns!4e967c6fe38e7c14!141.entry?wa=wsignin1.0
摘要: 全排列的生成算法就是对于给定的字符集,用有效的方法将所有可能的全排列无重复无遗漏地枚举出来。任何n个字符集的排列都可以与1~n的n个数字的排列一一对应,因此在此就以n个数字的排列为例说明排列的生成法。n个字符的全体排列之间存在一个确定的线性顺序关系。所有的排列中除最后一个排列外,都有一个后继;除第一个排列外,都有一个前驱。每个排列的后继都可以从 它 的前驱经过最少的变化而得到,全排列的生成算法就是...
阅读全文
void
test10_2(
void
)

{
static
char
const
*
szHexDigits
=
"
01
"
;
unsigned
char
b
=
16
;
cout
<<
szHexDigits[(b
>>
7
)
&
0x01
]
<<
szHexDigits[(b
>>
6
)
&
0x01
]
<<
'
'
;
cout
<<
szHexDigits[(b
>>
5
)
&
0x01
]
<<
szHexDigits[(b
>>
4
)
&
0x01
]
<<
'
'
;
cout
<<
szHexDigits[(b
>>
3
)
&
0x01
]
<<
szHexDigits[(b
>>
2
)
&
0x01
]
<<
'
'
;
cout
<<
szHexDigits[(b
>>
1
)
&
0x01
]
<<
szHexDigits[(b
>>
0
)
&
0x01
]
<<
'
'
;
}
void
test10_16(
void
)

{
static
char
const
*
szHexDigits
=
"
0123456789abcdef
"
;
unsigned
char
b
=
16
;
cout
<<
szHexDigits[(b
>>
4
)
&
0x0f
]
<<
szHexDigits[b
&
0x0f
]
<<
'
'
;
}