题解 | #输出单向链表中倒数第k个结点#
输出单向链表中倒数第k个结点
https://www.nowcoder.com/practice/54404a78aec1435a81150f15f899417d
#import <Foundation/Foundation.h>
int main(int argc, char* argv[]) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
char str1[1000];
char str2[100000];
char str3[1000];
int lineNum = 0;
while ((fgets(str1, sizeof(str1), stdin) != NULL) &&
(fgets(str2, sizeof(str2), stdin) != NULL) &&
(fgets(str3, sizeof(str3), stdin) != NULL) &&
lineNum <= 1000) {
str1[strcspn(str1, "\n")] = '\0';
str2[strcspn(str2, "\n")] = '\0';
str3[strcspn(str3, "\n")] = '\0';
int count = [[NSString stringWithFormat:@"%s", str1] intValue];
NSString* ocStr = [NSString stringWithFormat:@"%s", str2];
int index = [[NSString stringWithFormat:@"%s", str3] intValue];
NSMutableArray* array = [NSMutableArray array];
array = [ocStr componentsSeparatedByString:@" "];
int index2 = array.count - index;
printf("%@\n", [array objectAtIndex:index2]);
}
[pool drain];
return 0;
}
查看18道真题和解析