#import<Foundation/Foundation.h>StaticNSString *ConstKeyproductid =@"productId";//Product IDStaticNSString *ConstKeyproductprice =@"Productprice";//Commodity priceStaticNSString *ConstKeyproductname =@"ProductName";//Product NameStaticNSString *ConstKeyproductamount =@"Productamount";//Number of goods intMainintargcConst Char*argv[]) {@autoreleasepool {/** * The 1th question please replace the date of birth of your Social Security number with *, and output (ex: 210304******2248) * PS: Requires a maximum of 3 lines of code in addition to printing,*/NSLog (@"---------------The first question-------------"); NSString*str=@"210212199411033517"; NSString*STR2 = [str stringbyreplacingoccurrencesofstring:@"19941103"Withstring:@"******"]; NSLog (@"%@", STR2); /** Question 2nd ShoppingCart the product data stored in the shopping cart, please merge the same goods and export the combined product name, quantity, unit price, total*/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}]; NSLog (@"---------------The second question-------------"); Nsmutablearray*newarr=[[Nsmutablearray Alloc]initwitharray:shoppingcart]; intnum1=0, num2=0, num3=0; //NUM1 is the number of Ipod5, num2 is the number of iphone6s num3 the number of IPhone6 for(Nsdictionary *dicinchnewarr) { if([Dic[keyproductname] IsEqual:@"IPod5"]) {NUM1++; } Else if([Dic[keyproductname] IsEqual:@"iphone6s"]) {num2++; } Else if([Dic[keyproductname] IsEqual:@"IPhone6"]) {num3++; }} Nsset*Set=[Nsset Setwitharray:newarr]; for(Nsdictionary *dicinch Set){ intCount=[Dic[keyproductprice] intvalue]; if([Dic[keyproductname] IsEqual:@"IPod5"]) {NSLog (@"Item Number:%@ Product Name:%@ Quantity:%d Price:%@ total:%d", Dic[keyproductid], dic[keyproductname],num1,dic[keyproductprice],num1*count);} Else if([Dic[keyproductname] IsEqual:@"iphone6s"]) {NSLog (@"Item Number:%@ Product Name:%@ Quantity:%d Price:%@ total:%d", dic[keyproductid],dic[keyproductname],num2,dic[keyproductprice],num2*count); } Else if([Dic[keyproductname] IsEqual:@"IPhone6"]) {NSLog (@"Item Number:%@ Product Name:%@ Quantity:%d Price:%@ total:%d", dic[keyproductid],dic[keyproductname],num3,dic[keyproductprice],num3*count); } } } return 0;}
The implementation of the iOS shopping cart