请技术们指导做个EXE软件去重TXT文本。

去重文本信息

https://wwi.lanzout.com/iRNvYytzt2j 下载文本

去重文本 后面很多的格式都是这种格式的去重文本

img

img

这玩意儿做了怎么给你呢?exe

字符串操作 学会正则分隔 比对

能不能把需求说得具体一点?

我是将重复项进行分离,然后将不重复重新写入另一个文件。

#include <iostream>
#include<Windows.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <ostream>
#include <fstream>
using namespace std;

int main()
{
    ifstream myfile("def.txt");
    if (!myfile)
    {
        cout << "文件未打开" << endl;
        return 0;
    }
    vector<string> res;
    string s;
    while (getline(myfile, s))
    {
        int Count = count(res.begin(), res.end(), s);
        if (Count == 0)
        {
            res.push_back(s);
        }
    }
    myfile.close();
    ofstream outfile("gh.txt");
    if (!outfile.is_open())
    {
        cout << "打开文件失败" << endl;
    }
    for (int i = 0; i < res.size(); ++i)
    {
        outfile << res[i] << endl;
    }
    outfile.close();
        

    return 0;
}

带重复项文本

img


不带重复项文本

img

还有需要注意的是c++读取中文的时候有时候会乱码。解决方案就是将文本另存为另一个文件,编码选择ansi

img

相同的两道题是完全一样的吗?包括内容,格式?如果完全一样,大神应该可以做出来,我还差点。

去重是相同题目只要第一题吗,还是要完全相同的题目(题目与选项均相同)

题主还是说的不是太清楚,迷迷糊糊的,最好写出几个不符合的情况,方便大家按照要求来code


class Queue:
    def __init__(self, max_size):
        self.length = max_size
        self.List = [None] * max_size
        self.head = 0
        self.title = 0

    def clear(self):
        self.head = self.title = 0
        self.List = [None] * self.length

    # 入队
    def insert(self, data):
        if self.title == self.length:
            raise Exception("满队列")
        self.List[self.title] = data
        self.title += 1

    # 出队
    def remove(self):
        if self.title == self.head:
            raise Exception("空队列")
        data = self.List[self.head]
        self.head += 1
        return data

    def get_length(self):
        return self.title - self.head


class Removal:
    def __init__(self, file_path):
        self.content = self.get_content(file_path=file_path)

    def get_content(self, file_path):
        with open(file_path, 'r', encoding='utf-8') as file:
            content = file.read()
        return content

    def removal_data(self) -> list:
        string = self.content
        all_list = []
        list_content = string.split("\n\n")
        length = len(list_content)
        queue = Queue(max_size=length)
        # 入队
        for i in range(length):
            list_content[i] = list_content[i] + "\n\n"
            queue.insert(list_content[i])
        # 出队
        the_list = []
        for i in range(length):
            data = queue.remove()
            if '      ' not in data:
                all_list.append(the_list)
                the_list = []
            the_list.append(data)
        new_length = len(all_list)
        result = []
        for i in range(new_length):
            if len(all_list[i]) == 0:
                continue
            if all_list[i] not in result:
                result.append(all_list[i])
        return result

    # 写入
    def write(self):
        array = self.removal_data()
        with open("result.txt", 'w', encoding='utf-8') as f:
            f.close()
        length = len(array)
        array[-1][-5] = array[-1][-5].split("\n")[0]
        array[-1] = array[-1][:-4]
        for i in range(length):
            for j in range(len(array[i])):
                with open("result.txt", 'a+', encoding='utf-8') as file:
                    file.write(array[i][j])


if __name__ == '__main__':
    path = "./去重TXT文本.txt"
    User = Removal(file_path=path)
    User.write()

img

可以用队列来进行切分(类似于字符串的模式匹配),进行出队后用来去重,然后因为你的这个最后一个问题和第一个问题会循环,所以我拿\n再做了一次切分,有用的话点一下采纳,要生成exe文件就pyinstall -F 名字.py,在dist文件夹下会有一个exe程序

写成品没问题.教就麻烦

老哥,我写完了
你加我微信给你 Twy19521,exe
不方便的话,你也可以直接私信我,我给你发邮箱

img

img

img

img

img

我主要用的就是先把问题放进去,然后我们用一个判断去找到我们选项的结束,然后在写进去,给你用tk写了一个小界面,我们直接把文件路径放进去,点击获取就可以了,他会直接在你这个exe当前目录下生成一个txt,唯一的问题就是在获取第一个的时候会重复,但是其他的都是正常的