Skip to content

Commit d0d0580

Browse files
author
lazylzg
committed
Update test3-7找位置.cpp
1 parent 092cb42 commit d0d0580

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

第3章排序与查找/3.2查找/test3-7找位置.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@ int main() {
66
string str;
77
while(cin>>str) {
88
for(int i=0; i<str.size(); i++) {
9-
bool first=false;//ÖØ¸´×Ö·ûµÄµÚÒ»´Î³öÏÖ
9+
bool isFirst=false;
10+
//Èç¹û×ÖĸÒѱéÀú
1011
if(str[i]=='*')continue;
1112
for(int j=i+1; j<str.size(); j++) {
1213
if(str[i]==str[j]) {
13-
if(!first) {
14-
printf("%c:%d",str[i],i);
15-
first=true;
14+
if(!isFirst) {
15+
printf("%c:%d",str[j],i);
16+
isFirst=true;
1617
}
1718
printf(",%c:%d",str[j],j);
18-
str[j]='*';
19+
str[j]='*';//񄱎˜
1920
}
2021
}
21-
if(first) {
22-
printf("\n");
23-
}
22+
if(isFirst)printf("\n");
2423
}
2524
}
2625
return 0;

0 commit comments

Comments
 (0)