- #import <Foundation/Foundation.h>
- //输出一个字符串中每个字符出现的次数
- int main() {
- NSMutableString *str = [[NSMutableString alloc] initWithFormat:@"asdkjafawfauwiufawefp"];
-
- // NSMutableArray *array ;
- for (int i = 0;i<str.length;i++)
- {
- unichar c1 = [str characterAtIndex:i];
-
- int count =0;
- for (int j = 0; j<str.length; j++)
- {
- unichar c2 = [str characterAtIndex:j];
- if (c1 == c2)
- {
- count++;
- }
- }
- NSLog(@"%c有%d个\n",c1,count);
- }
- return 0;
- }
复制代码
倒是可以求出每个字符出现的字数,可是想了半天没解决重复的问题,麻烦大神帮个忙!非常感谢! |
|