1.假設(shè)有一個(gè)字符串a(chǎn)abcad,請(qǐng)寫一段程序,去掉字符串中不相鄰的重復(fù)字符串锋叨,即上述字符串處理之后的輸出結(jié)果為:aabcd
NSMutableString * str = [[NSMutableString alloc]initWithFormat;@“aabcad”];
for (int i = 0 ,i < str.length - 1 ;i++){
unsigned char a = [str characterAtIndex:i];
for (int j = i + 1 ,j < str.length ,j++){
unsigned char b = [str characterAtIndex:j];
if (a == b ){
if (j == i + 1){
}else{
[str deleteCharactersInRange:NSMakeRange(j, 1)];
}
}
}
}
NSLog(@“%@”,str);