题解 | #数字颠倒#
数字颠倒
https://www.nowcoder.com/practice/ae809795fca34687a48b172186e3dafe
#import <Foundation/Foundation.h>
int main(int argc, char* argv[]) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
char inputNumber[10000000];
if (scanf("%s", inputNumber) != EOF) {
// printf("%s", inputNumber);
}
// 倒序存入数组中
NSMutableArray *reverseArray = [NSMutableArray array];
NSUInteger length = strlen(inputNumber);
for (int i = length - 1; i >= 0; i--) {
[reverseArray addObject:[NSString stringWithFormat:@"%c", inputNumber[i]]];
}
// 打印
for (int j = 0; j < length; j++) {
printf("%@", [reverseArray objectAtIndex:j]);
}
[pool drain];
return 0;
}
查看12道真题和解析