#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//定义一个可变字典
NSMutableDictionary *mdic=[NSMutableDictionary dictionary];
NSString *index=[NSString string];
for (int i=0; i<3; i++) {
NSLog(@"请输入一个学生姓名 学号");
char ch[20];
gets(ch);
//变为OC字符串
NSString *str=[NSString stringWithFormat:@"%s",ch];
NSArray *arr=[str componentsSeparatedByString:@" "];
//保存到字典
[mdic setObject:arr[0] forKey:arr[1]];
if (i==1) {
index =arr[1];
}
}
//删除下标为1的字典
[mdic removeObjectForKey:index];
NSLog(@"%@",mdic);
}
return 0;
} |
|