介紹一下思路:
(ps:在這裡一定要注意其中的字串的替換函式replace函式,為了這個我可是折騰了不少時間)
總體來說還是遍歷字串;
思路一:
1遍歷字串a去除字串a中所有的重複的字串後的字元,變成非重複的字串b;
2迴圈遍歷字串b將所有的字串b中的單字元與字串a中的單字元進行比較,如果找到了重複的重複的字串就就加1,否則不操作;
3一次遍歷完a後列印此時的操作的字串的個數;
**如下:
teststr="abcdabcd"
result=""
for i=1 to len(teststr)
if instr(1,result,mid(teststr,i,1),1)>0 then
' teststr=replace(teststr,mid(teststr,i,1),"")
wscript.echo teststr
else
result=result+mid(teststr,i,1)
endifnext
msgbox result
mytest=""
for k=1 to len(result)
resk=mid(result,k,1)
value=0
for t=1 to len(teststr)
rest=mid(teststr,t,1)
if resk=rest then
value=value+1
endifnext
mytest=mytest&"字串為"&resk&" 次數為:"&value&vbcrlf
next
msgbox mytest
思路二:
兩次迴圈遍及字串,第i項的值與第i+1項的值是否相等,如果相等就自增計數器;
msgbox result"abcdabcd323f3f3ef3efwedwewdwedwdewe3r435t4wdewdwe"
""for
tofor
toif
then
" "' teststr=replace(teststr,mid(teststr,i,1),"")
endif
next
ifand
" "then
"字元為:"
"出現次數為:"
endif
next
去除重複字串
建立新集合將重複元素去掉 1,明確返回值型別,返回arraylist 2,明確引數列表arraylist 分析 1,建立新集合 2,根據傳入的集合 老集合 獲取迭代器 3,遍歷老集合 4,通過新集合判斷是否包含老集合中的元素,如果包含就不新增,如果不包含就新增 public static array...
c 字串 去除重複字元
輸入乙個字串,去掉重複字元後輸出。輸入樣例 abcaadefb輸出樣例 abcdef實現方法 void encrypt char keych,char key if flag keych j 1 0 完整程式 include include using namespace std define ma...
去除字串中重複字元
設計演算法並寫出 移除字串中重複的字元,不能使用額外的快取空間。注意 可以使用額外的乙個或兩個變數,但不允許額外再開乙個陣列拷貝。進一步地,為你的程式寫測試用例。這道題目其實是要你就地 in place 將字串中重複字元移除。你可以向面試官問清楚,不能使用額外的乙份陣列拷貝是指根本就不允許開乙個陣列...