| |

VerySource

 Forgot password?
 Register
Search
Author: yunshenxin

Text deduplication algorithm problem ~~ Please give pointers

[Copy link]

0

Threads

34

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-3-29 10:45:01
| Show all posts
20161217, D, B, DKDDA332021, ESA3332SS1
20161217, D, B, DKDDA332022, ESA3332SS2
20161217, D, B, DKDDA332023, ESA3332SS3
20161217, D, B, DKDDA332021, ESA3332SS2
20161217, D, B, DKDDA332025, ESA3332SS2
20161217, D, B, DKDDA332021, ESA3332SS3
20161217, D, B, DKDDA332022, ESA3332SS7

Brother 唉, look at it, DKDDA332021 is completely deleted, because there is a duplicate 唉 in the second judgment based on S5, unfortunately 唉 you take a good look
If you want to optimize this algorithm, it is very complicated.
Reply

Use magic Report

0

Threads

34

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-3-29 16:15:01
| Show all posts
After clearing S4, this is the result:
20161217, D, B, DKDDA332021, ESA3332SS3
20161217, D, B, DKDDA332022, ESA3332SS7
20161217, D, B, DKDDA332023, ESA3332SS3
20161217, D, B, DKDDA332025, ESA3332SS2
Then, unfortunately, the line 20161217, D, B, DKDDA332021, ESA3332SS3, because ESA3332SS3 has duplicates with it, so it was ruined
Reply

Use magic Report

0

Threads

25

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-3-29 20:45:01
| Show all posts
function CompareS4 (Item1, Item2: Pointer): Integer;
begin
  Result: = CompareText (TStrings (Item1) [3], TStringList (Item2) [3]);
end;

function CompareS5 (Item1, Item2: Pointer): Integer;
begin
  Result: = CompareText (TStrings (Item1) [4], TStringList (Item2) [4]);
end;

procedure TFormDemo.ButtonRemoveClick (Sender: TObject);
var
  StringsList: TList;
  Strings: TStrings;
  TmpStrings: TStrings;
  Idx: Integer;
begin
  if OpenDialog.Execute then
  begin
    Memo.Lines.LoadFromFile (OpenDialog.FileName);

    // Write data to List
    StringsList: = TList.Create;
    for Idx: = 0 to Pred (Memo.Lines.Count) do
    begin
      Strings: = TStringList.Create;
      Strings.Delimiter: = ',';
      Strings.DelimitedText: = Memo.Lines [Idx];
      StringsList.Add (Pointer (Strings));
    end;

    TmpStrings: = TStringList.Create;

    // Delete the same line in S4
    StringsList.Sort (CompareS4); // Sort by S4
    TmpStrings.Assign (TStrings (StringsList.Items [Pred (StringsList.Count)]));
    for Idx: = Pred (StringsList.Count-1) downto 0 do
    begin
      if TmpStrings [3] = TStrings (StringsList.Items [Idx]) [3] then
        StringsList.Delete (Idx)
      else
        TmpStrings.Assign (TStrings (StringsList.Items [Idx]));
    end;

    // Delete the same line in S5
    StringsList.Sort (CompareS5); // Sort by S5
    TmpStrings.Assign (TStrings (StringsList.Items [Pred (StringsList.Count)]));
    for Idx: = Pred (StringsList.Count-1) downto 0 do
    begin
      if TmpStrings [4] = TStrings (StringsList.Items [Idx]) [4] then
        StringsList.Delete (Idx)
      else
        TmpStrings.Assign (TStrings (StringsList.Items [Idx]));
    end;

    // Write data back to MEMO
    Memo.Clear;
    for Idx: = 0 to Pred (StringsList.Count) do
    begin
      Memo.Lines.Add (TStrings (StringsList.Items [Idx]). DelimitedText);
    end;

    // Write data back to the document
    Memo.Lines.SaveToFile (OpenDialog.FileName);
  end;
end;
Reply

Use magic Report

4

Threads

19

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

 Author| Post time: 2020-3-29 21:45:01
| Show all posts
Oh my god, clear skies ~ Thank you very much ~ Your algorithm is very good ~~ I have met my requirements ~~ Thank you very much ~~
Reply

Use magic Report

0

Threads

34

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-3-29 23:30:01
| Show all posts
Gaga ~~ Thank you for your compliment 唉
Reply

Use magic Report

4

Threads

19

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

 Author| Post time: 2020-3-30 10:30:02
| Show all posts
So many people help, thank you very much ~ `Touched ~
Reply

Use magic Report

4

Threads

19

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

 Author| Post time: 2020-3-30 20:45:01
| Show all posts
suppermanWhen you run your program, it will cross the border ~ look at it
Reply

Use magic Report

0

Threads

25

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-3-31 03:15:02
| Show all posts
suppermanWhen you run your program, it will cross the border ~ look at it
=========================
Will not cross the border.
Reply

Use magic Report

0

Threads

25

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-3-31 11:45:01
| Show all posts
Operation result
======
20161217, D, B, DKDDA332021, ESA3332SS1
20161217, D, B, DKDDA332022, ESA3332SS2
20161217, D, B, DKDDA332023, ESA3332SS3
Reply

Use magic Report

4

Threads

19

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

 Author| Post time: 2020-3-31 20:00:02
| Show all posts
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, StrUtils;

type
  TForm1 = class (TForm)
    Button1: TButton;
    OpenDialog: TOpenDialog;
    Memo: TMemo;
    procedure Button1Click (Sender: TObject);
  private
    {Private declarations}
  public
    {Public declarations}
  end;

var
  Form1: TForm1;

implementation

{$ R * .dfm}
function CompareS4 (Item1, Item2: Pointer): Integer;
begin
  Result: = CompareText (TStrings (Item1) [3], TStringList (Item2) [3]);
end;

function CompareS5 (Item1, Item2: Pointer): Integer;
begin
  Result: = CompareText (TStrings (Item1) [4], TStringList (Item2) [4]);
end;
procedure TForm1.Button1Click (Sender: TObject);
var
  StringsList: TList;
  Strings: TStrings;
  TmpStrings: TStrings;
  Idx: Integer;
begin
  if OpenDialog.Execute then
  begin
    Memo.Lines.LoadFromFile (OpenDialog.FileName);

    // Write data to List
    StringsList: = TList.Create;
    for Idx: = 0 to Pred (Memo.Lines.Count) do
    begin
      Strings: = TStringList.Create;
      Strings.Delimiter: = ',';
      Strings.DelimitedText: = Memo.Lines [Idx];
      StringsList.Add (Pointer (Strings));
    end;

    TmpStrings: = TStringList.Create;

    // Delete the same line in S4
    StringsList.Sort (CompareS4); // Sort by S4
    TmpStrings.Assign (TStrings (StringsList.Items [Pred (StringsList.Count)]));
    for Idx: = Pred (StringsList.Count-1) downto 0 do
    begin
      if TmpStrings [3] = TStrings (StringsList.Items [Idx]) [3] then
        StringsList.Delete (Idx)
      else
        TmpStrings.Assign (TStrings (StringsList.Items [Idx]));
    end;

    // Delete the same line in S5
    StringsList.Sort (CompareS5); // Sort by S5
    TmpStrings.Assign (TStrings (StringsList.Items [Pred (StringsList.Count)]));
    for Idx: = Pred (StringsList.Count-1) downto 0 do
    begin
      if TmpStrings [4] = TStrings (StringsList.Items [Idx]) [4] then
        StringsList.Delete (Idx)
      else
        TmpStrings.Assign (TStrings (StringsList.Items [Idx]));
    end;

    // Write data back to MEMO
    Memo.Clear;
    for Idx: = 0 to Pred (StringsList.Count) do
    begin
      Memo.Lines.Add (TStrings (StringsList.Items [Idx]). DelimitedText);
    end;

    // Write data back to the document
    Memo.Lines.SaveToFile (OpenDialog.FileName);
  end;
end;




end.


Error prompt http://www.kongqiqiu.com/down/text.jpg
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list