#import <Foundation/Foundation.h> char str0[100]; int max=0;
int main(int argc, const char * argv[]) { @autoreleasepool { //输入一个字符串 NSLog(@"请输入一个字符串:"); gets(str0);
NSString *str = [NSString stringWithFormat:@"%s",str0];
NSLog(@"您数入的字符串:%@",str);
//将字符串准换成数组 NSArray *arr = [str componentsSeparatedByString:@" "];
//找出数组的最大长度 for (int i = 0; i<arr.count; i++) { max = (max>(int)[arr length])?max:(int)[arr length]; }
//将所以最大长度的元素输出 for (int i = 0; i<arr.count; i++) { if ((int)[arr length]==max) { NSLog(@"最大长度的字符串为:%@,长度为%d",arr,max); } } } return 0; }
|