?
?1
//
?Pyin.cpp?:?定義控制臺應(yīng)用程序的入口點(diǎn)。
?2
//
?3
?4
#include?
"
stdafx.h
"
?5
using
?
namespace
?std;
?6
?7
char
?GetPYChar(
char
?
*
?c)
?8
{
?9
????unsigned?
char
?
*
?array?
=
?
new
?unsigned?
char
[
2
];
10
????array[
0
]
=
c[
0
];
11
????array[
1
]
=
c[
1
];
12
????
int
?i?
=
?(
short
)(array[
0
]?
-
?
'
\0
'
)?
*
?
256
?
+
?((
short
)(array[
1
]?
-
?
'
\0
'
));
13
14
????
if
?(?i?
<
?
0xB0A1
)?
return
?
'
*
'
;
15
????
if
?(?i?
<
?
0xB0C5
)?
return
?
'
a
'
;
16
????
if
?(?i?
<
?
0xB2C1
)?
return
?
'
b
'
;
17
????
if
?(?i?
<
?
0xB4EE
)?
return
?
'
c
'
;
18
????
if
?(?i?
<
?
0xB6EA
)?
return
?
'
d
'
;
19
????
if
?(?i?
<
?
0xB7A2
)?
return
?
'
e
'
;
20
????
if
?(?i?
<
?
0xB8C1
)?
return
?
'
f
'
;
21
????
if
?(?i?
<
?
0xB9FE
)?
return
?
'
g
'
;
22
????
if
?(?i?
<
?
0xBBF7
)?
return
?
'
h
'
;
23
????
if
?(?i?
<
?
0xBFA6
)?
return
?
'
g
'
;
24
????
if
?(?i?
<
?
0xC0AC
)?
return
?
'
k
'
;
25
????
if
?(?i?
<
?
0xC2E8
)?
return
?
'
l
'
;
26
????
if
?(?i?
<
?
0xC4C3
)?
return
?
'
m
'
;
27
????
if
?(?i?
<
?
0xC5B6
)?
return
?
'
n
'
;
28
????
if
?(?i?
<
?
0xC5BE
)?
return
?
'
o
'
;
29
????
if
?(?i?
<
?
0xC6DA
)?
return
?
'
p
'
;
30
????
if
?(?i?
<
?
0xC8BB
)?
return
?
'
q
'
;
31
????
if
?(?i?
<
?
0xC8F6
)?
return
?
'
r
'
;
32
????
if
?(?i?
<
?
0xCBFA
)?
return
?
'
s
'
;
33
????
if
?(?i?
<
?
0xCDDA
)?
return
?
'
t
'
;
34
????
if
?(?i?
<
?
0xCEF4
)?
return
?
'
w
'
;
35
????
if
?(?i?
<
?
0xD1B9
)?
return
?
'
x
'
;
36
????
if
?(?i?
<
?
0xD4D1
)?
return
?
'
y
'
;
37
????
if
?(?i?
<
?
0xD7FA
)?
return
?
'
z
'
;
38
????
return
?
'
*
'
;
39
}
40
41
int
?_tmain(
int
?argc,?_TCHAR
*
?argv[])
42
{
43
????
char
*
?szArray?
=
?
new
?
char
[
10
];
44
????strcpy(szArray,
"
朱王
"
);
45
????
char
*
?charptr?
=
?szArray;
46
????cout
<<
szArray
<<
endl;
47
????
48
????cout
<<
sizeof
?szArray
<<
endl;
49
????cout
<<
GetPYChar(charptr)
<<
endl;
50
????cout
<<
GetPYChar(charptr
+
2
)
<<
endl;
51
????system(
"
PAUSE
"
);
52
53
????
return
?
0
;
54
}
55
56
//
?Pyin.cpp?:?定義控制臺應(yīng)用程序的入口點(diǎn)。?2
//?3
?4
#include?
"
stdafx.h
"
?5
using
?
namespace
?std;?6
?7
char
?GetPYChar(
char
?
*
?c)?8
{?9
????unsigned?
char
?
*
?array?
=
?
new
?unsigned?
char
[
2
];10
????array[
0
]
=
c[
0
];11
????array[
1
]
=
c[
1
];12
????
int
?i?
=
?(
short
)(array[
0
]?
-
?
'
\0
'
)?
*
?
256
?
+
?((
short
)(array[
1
]?
-
?
'
\0
'
));13
14
????
if
?(?i?
<
?
0xB0A1
)?
return
?
'
*
'
;15
????
if
?(?i?
<
?
0xB0C5
)?
return
?
'
a
'
;16
????
if
?(?i?
<
?
0xB2C1
)?
return
?
'
b
'
;17
????
if
?(?i?
<
?
0xB4EE
)?
return
?
'
c
'
;18
????
if
?(?i?
<
?
0xB6EA
)?
return
?
'
d
'
;19
????
if
?(?i?
<
?
0xB7A2
)?
return
?
'
e
'
;20
????
if
?(?i?
<
?
0xB8C1
)?
return
?
'
f
'
;21
????
if
?(?i?
<
?
0xB9FE
)?
return
?
'
g
'
;22
????
if
?(?i?
<
?
0xBBF7
)?
return
?
'
h
'
;23
????
if
?(?i?
<
?
0xBFA6
)?
return
?
'
g
'
;24
????
if
?(?i?
<
?
0xC0AC
)?
return
?
'
k
'
;25
????
if
?(?i?
<
?
0xC2E8
)?
return
?
'
l
'
;26
????
if
?(?i?
<
?
0xC4C3
)?
return
?
'
m
'
;27
????
if
?(?i?
<
?
0xC5B6
)?
return
?
'
n
'
;28
????
if
?(?i?
<
?
0xC5BE
)?
return
?
'
o
'
;29
????
if
?(?i?
<
?
0xC6DA
)?
return
?
'
p
'
;30
????
if
?(?i?
<
?
0xC8BB
)?
return
?
'
q
'
;31
????
if
?(?i?
<
?
0xC8F6
)?
return
?
'
r
'
;32
????
if
?(?i?
<
?
0xCBFA
)?
return
?
'
s
'
;33
????
if
?(?i?
<
?
0xCDDA
)?
return
?
'
t
'
;34
????
if
?(?i?
<
?
0xCEF4
)?
return
?
'
w
'
;35
????
if
?(?i?
<
?
0xD1B9
)?
return
?
'
x
'
;36
????
if
?(?i?
<
?
0xD4D1
)?
return
?
'
y
'
;37
????
if
?(?i?
<
?
0xD7FA
)?
return
?
'
z
'
;38
????
return
?
'
*
'
;39
}
40
41
int
?_tmain(
int
?argc,?_TCHAR
*
?argv[])42
{43
????
char
*
?szArray?
=
?
new
?
char
[
10
];44
????strcpy(szArray,
"
朱王
"
);45
????
char
*
?charptr?
=
?szArray;46
????cout
<<
szArray
<<
endl;47
????48
????cout
<<
sizeof
?szArray
<<
endl;49
????cout
<<
GetPYChar(charptr)
<<
endl;50
????cout
<<
GetPYChar(charptr
+
2
)
<<
endl;51
????system(
"
PAUSE
"
);52
53
????
return
?
0
;54
}
55
56
老同學(xué)做小小的編程設(shè)計(jì),電話號碼本,希望增加一個(gè)輸入姓名漢語拼音首字母的方式快速找到條目,不知道如何實(shí)現(xiàn)。我就找了一下,覺得按照這種思路最簡單。
首先在條目的數(shù)據(jù)結(jié)構(gòu)中增加一個(gè)動(dòng)態(tài)字符串,在生成節(jié)點(diǎn)的時(shí)候動(dòng)態(tài)的把姓名的拼音準(zhǔn)備好。等到用這個(gè)方法搜索條目的時(shí)候只需要對比拼音索引,返回符合條件的節(jié)點(diǎn)指針就可以了。


