题解 | #字符串字符匹配#

字符串字符匹配

https://www.nowcoder.com/practice/22fdeb9610ef426f9505e3ab60164c93

#import <Foundation/Foundation.h>

int main(int argc, char* argv[]) {
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    
    char shortStr[1000];
    char longStr[1000];

    gets(shortStr);
    gets(longStr);

    NSString *longOCString = [NSString stringWithFormat:@"%s", longStr];
    NSMutableArray *shortArray = [NSMutableArray array];
    BOOL AllAppeared = YES;

    // 只要有一个字符没出现过就返回false
    for (int i = 0; i < strlen(shortStr); i++) {
        if (![longOCString containsString:[NSString stringWithFormat:@"%c", shortStr[i]]]) {
            AllAppeared = NO;
        }
    }

    if (AllAppeared) {
        printf("true");
    }
    else {
        printf("false");
    }

    [pool drain];
    return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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