//
#import <Foundation/Foundation.h>
static NSString * const keyProductId = @"productId";//商品ID
static NSString * const keyProductPrice = @"productPrice";//商品价格
static NSString * const keyProductName = @"productName";//商品名称
static NSString * const keyProductAmount = @"productAmount";//商品数量
int main(int argc, const char * argv[]) {
@autoreleasepool {
/**
* 第1题 请将你的身份证号的出生日期部分用*代替,并输出(例如:210304******2248)
* PS:要求除打印外,代码行数最多为3行,
*/
NSString *[email protected]"220104199401043814";
NSString *newstr3=[str stringByReplacingOccurrencesOfString:@"19940104" withString:@"*******" ];
NSLog(@"%@",newstr3);
/**
* 第2题 shoppingCart 为购物车中存储的商品数据,请对相同的商品进行商品合并,并输出合并后的商品名称,数量,单价,合计
*/
NSArray *shoppingCart = @[@{keyProductId:@"A1001",
keyProductName:@"iPod5",
keyProductPrice:@1488.0,
keyProductAmount:@1},
@{keyProductId:@"A1003",
keyProductName:@"iPhone6",
keyProductPrice:@4488.0,
keyProductAmount:@1},
@{keyProductId:@"A1001",
keyProductName:@"iPod5",
keyProductPrice:@1488.0,
keyProductAmount:@1},
@{keyProductId:@"A1002",
keyProductName:@"iPhone6s",
keyProductPrice:@5288.0,
keyProductAmount:@1},
@{keyProductId:@"A1003",
keyProductName:@"iPhone6",
keyProductPrice:@4488.0,
keyProductAmount:@1},
@{keyProductId:@"A1001",
keyProductName:@"iPod5",
keyProductPrice:@1488.0,
keyProductAmount:@1}];
NSMutableArray *mutArr=[[NSMutableArray alloc]init];
NSArray *arr=[[NSArray alloc]init];
[mutArr addObjectsFromArray:shoppingCart];
for (int i=0;i<mutArr.count;i++){
NSDictionary *dic=mutArr[i];
if ( [[ dic objectForKey:keyProductId] isEqual:@"A1001"]) {
int numA1001;
int price=[dic[keyProductPrice] intValue];
numA1001++;
if (numA1001==3) {
NSLog(@" 名称:%@ 数量%d 单价%@ 合计%d ",dic[keyProductName],numA1001,dic[keyProductPrice],numA1001* price);
}
}
}
for (int i=0;i<mutArr.count;i++){
NSDictionary *dic=mutArr[i];
if ( [[ dic objectForKey:keyProductId] isEqual:@"A1002"]) {
int numA1002;
int price=[dic[keyProductPrice] intValue];
numA1002++;
if (numA1002==1) {
NSLog(@" 名称:%@ 数量%d 单价%@ 合计%d ",dic[keyProductName],numA1002,dic[keyProductPrice],numA1002* price);
}
}
}
for (int i=0;i<mutArr.count;i++){
NSDictionary *dic=mutArr[i];
if ( [[ dic objectForKey:keyProductId] isEqual:@"A1003"]) {
int numA1003;
int price=[dic[keyProductPrice] intValue];
numA1003++;
if (numA1003==2) {
NSLog(@" 名称:%@ 数量%d 单价%@ 合计%d ",dic[keyProductName],numA1003,dic[keyProductPrice],numA1003* price);
}
}
}
}
return 0;
}