1.假设有一个字符串aabcad,请写一段程序,去掉字符串中不相邻的重复字符串,即上述字符串处理之后的输出结果为: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);