/*
5 依据输入的内容打印出菱形
*/
+(void)print:(NSInteger)count blankString:(NSString*)blankString flagString:(NSString*)flagString
/*
{
NSMutableString * ptr = [[NSMutableString alloc]init];
for (NSInteger i = 0; i < count; i++) {
for (NSInteger j = 0; j < count; j++) {
if (abs((int)(i-count/2))+abs((int)(j - count/2))==count/2) {
[ptr appendString:flagString];
}
else
{
[ptr appendString:blankString];
}
}
[ptr appendString:@"\n"];
}
NSLog(@"\n%@",ptr);
}
*/
{
NSMutableString * ptr = [[NSMutableString alloc]init];
for (NSInteger i = 0; i < count; i++) {
for (NSInteger j = 0; j < count; j++) {
if (abs((int)(i - count/2))+abs((int)(j - count/2))==count/2) {
[ptr appendString:flagString];
}
else
{
[ptr appendString:blankString];
}
}
[ptr appendString:@"\n"];
}
NSLog(@"\n%@",ptr);
}
//count 表示正方形边长
//flagString 组成菱形的边
//blankString 组成背景正方形
//比方 [class print:5 blankString:@“+”flagString:@“#”];
/*
+ + # + +
+ # + # +
# + + + #
+ # + # +
+ + # + +
*/
/*
转载于:https://www.cnblogs.com/zhchoutai/p/6760171.html