题解 | #密码忘了怎么办?#

密码忘了怎么办?

https://ac.nowcoder.com/acm/contest/35358/C

操作系统编程基础

巧了不是,下午实验课刚好写了一个简单版本的cp脚本。咱直接来个爆搜密码

//InzamZ
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#include "dirent.h"
#include <sys/stat.h>
#include <sys/types.h>

int scanDir(char *path, char *filePath) {
    DIR *dir;
    struct dirent *ptr;
    char base[1000];
    if ((dir = opendir(path)) == NULL) {
        perror("Open dir error...");
        exit(1);
    }
    while ((ptr = readdir(dir)) != NULL) {
        if (strcmp(ptr->d_name, ".") == 0 || strcmp(ptr->d_name, "..") == 0)
            continue;
        else if (ptr->d_type == 8) {
            FILE *fp;
            char dirr[1000];
            strcpy(dirr, path);
            strcat(dirr, "/");
            strcat(dirr, ptr->d_name);
            fp = fopen(dirr, "r");
            if (fp == NULL) {
                perror("Open file error...");
                exit(1);
            }
            char ch[100];
            while (fgets(ch, 100, fp) != NULL) {
                if (strcmp(ch, "114514") != 0) {
                    printf("%s", ch);
                    printf("%s", dirr);
                    exit(1);
                }
            }
        }
        else if (ptr->d_type == 4) {
            // dir
            strcpy(base, path);
            strcat(base, "/");
            strcat(base, ptr->d_name);
            scanDir(base, filePath);
        }
    }
    closedir(dir);
    return 0;
}

signed main() {
    DIR *dir;
    struct dirent *ptr;
    char base_path[100] = "/home/user/桌面/风行迷踪";
    scanDir(base_path, base_path);
    return 0;
}

全部评论
如果是 *nix 系统的话,这几行就可以哈哈。 ``` for x in $(find . -type f) do out=$(cat $x) if [ "$out" != "114514" ]; then echo $x fi done ```
1 回复 分享
发布于 2022-06-01 21:51
大佬!!!
点赞 回复 分享
发布于 2022-06-01 21:10

相关推荐

大叔叔1:你把自己说的话打码,所以你想表达什么
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务