题解 | #输出单向链表中倒数第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;
}

全部评论

相关推荐

刷牛客的我很豁达:你是不是对算法有什么误解,你没手握两篇顶刊顶会,还想搞算法岗,有顶刊顶会在算法岗算才入门
点赞 评论 收藏
分享
迷茫的大四🐶:这就是他们口中的ai时代的一人公司
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务