1 NSArray *jiangsu = [[NSArray alloc]initWithObjects:@"nanjing",@"suzhou",@"wuxi",@"changzhou", nil]; 2 3 NSArray *henan = [[NSArray alloc]initWithObjects:@"sanmenxia",@"zhengzhou",@"kaifeng",nil]; 4 5 6 7 NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:jiangsu,@"jiangsu",henan,@"henan", nil]; 8 9 // NSLog(@"%@",jiangsu); 10 11 12 NSLog(@"请输入城市名称(拼音):"); 13 14 char str[10]; 15 scanf(" %s",str); 16 17 NSString *str2 = [[NSString alloc]initWithUTF8String:str]; 18 19 // NSArray *arr = [[NSArray alloc]init]; 20 // 21 // arr = [dic allValues]; 22 23 24 // bool result = NO; 25 26 for(NSArray *temp in [dic allValues]) 27 { 28 for(NSString *tmp in temp) 29 { 30 if([tmp isEqualToString:str2]) 31 { 32 NSString *str3 = [[dic allKeysForObject:temp] objectAtIndex:0]; 33 34 NSLog(@"%@",str3); 35 // result = YES; 36 break; 37 } 38 } 39 40 }
时间: 2024-11-05 12:25:25