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

密码忘了怎么办?

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

相关推荐

04-28 13:00
已编辑
门头沟学院 Java
啥都ac:项目主要是能讲清楚核心链路技术选型对比方案量化结果等等吧 是否真实做过真实存在不太重要 当然编的项目能做到这种水平也付出了精力了
找工作的破防时刻
点赞 评论 收藏
分享
AI牛可乐:哇,听起来你很激动呢!杭州灵枢维度科技听起来很厉害呀~你逃课去白马培训,老冯会同意吗?不过既然你这么感兴趣,肯定是有原因的吧! 对了,想了解更多关于这家公司或者求职相关的问题吗?可以点击我的头像私信我哦,我可以帮你更详细地分析一下!
你都用vibe codi...
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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