2012-06-30 17:50:54Morris

[趣題] dolls.rar 解開所有的壓縮檔吧!

我並曉得如何描述這一題, 但這個檔案就是壓縮檔中有壓縮檔, 總共 2048 個壓縮檔,
你的任務就是要將這一個壓縮檔全解開, 最後會有 2048 個 txt 文字檔, 而其中一個是密碼,
請你找出密碼!

當然先給 dolls.rar 的載點囉

http://www.mediafire.com/?tne2fmzbndp53ia


在這題學習到了使用 C++ 的 cmd, chdir 代替 cd 指令,
叫出 winrar 的子目錄, 使用 rar, 或 unrar 中的指令 ... 等


#include <iostream>

#include <dirent.h>
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <set>
using namespace std;

int main() {
    //system("cd C:\\Program Files (x86)\\WinRAR");
    //system("cd C:\\Users\\owner\\Desktop\\Dolls");
    char unrar_target[] = "C:\\Users\\owner\\Desktop\\Dolls";
    while(1) {
        DIR *dirp;
        struct dirent *entry;
        set<string> rarDoc;
        int has = 0;
        if(dirp = opendir(unrar_target)) {
            while(entry = readdir(dirp)) {
                if(strlen(entry->d_name) > 4) {
                    int len = strlen(entry->d_name);
                    if(!strcmp(entry->d_name+len-4, ".rar")) {
                        //cout << entry->d_name << endl;
                        if(rarDoc.find(entry->d_name) == rarDoc.end()) {
                            rarDoc.insert(entry->d_name);
                            has = 1;
                        }
                    }
                }
            }
            closedir(dirp);
        }
        if(has == 0)
            break;
        chdir("C:\\Program Files (x86)\\WinRAR");
        //system("dir");
        string path(unrar_target);
        string cmd = "rar e -o- -mt6 " + path + "\\*.rar " + path;
        cout << cmd << endl;
        system(cmd.c_str());
        /*for(set<string>::iterator i = rarDoc.begin(); i != rarDoc.end(); i++) {
            string unrar_cmd = "unrar e " + path + "\\" + *i + " " + path;
            cout << unrar_cmd << endl;
            system(unrar_cmd.c_str());
        }*/
        chdir(unrar_target);
        for(set<string>::iterator i = rarDoc.begin(); i != rarDoc.end(); i++) {
            string cmd = "DEL " + path + "\\" + *i;
            //cout << cmd << endl;
            system(cmd.c_str());
        }
    }
    return 0;
}