| |

VerySource

 Forgot password?
 Register
Search
View: 825|Reply: 4

I have encountered an algorithm problem for a long time and haven't solved it, help me

[Copy link]

4

Threads

19

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-1-28 13:40:02
| Show all posts |Read mode
The text document content is as follows

 // s1 s2 s3 s4 s5
20061217, D, B, DKDDA332021, ESA3332SS1
20061217, D, B, DKDDA332022, ESA3332SS2
20061217, D, B, DKDDA332023, ESA3332SS3
20061217, D, B, DKDDA332021, ESA3332SS2
20061217, D, B, DKDDA332025, ESA3332SS2
20061217, D, B, DKDDA332021, ESA3332SS3
20061217, D, B, DKDDA332022, ESA3332SS7

Among the text documents, s4 and s5 will have duplicate data. I want to delete all the duplicates.
But with SORT sort, you can only sort the entire row. Can you sort by s4 and s4, and delete the duplicate capacity (the entire row)! Thank you everyone
Reply

Use magic Report

0

Threads

34

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-2-24 12:00:01
| Show all posts
Clarify the condition: "Delete the row as long as S4 and S5 are the same in a row" or "In all rows, where S4 is the same, only one row is left, and the remaining rows are deleted; where S5 is the same, only the left Delete one line and the rest "?
Reply

Use magic Report

4

Threads

19

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

 Author| Post time: 2020-2-29 21:15:01
| Show all posts
Where S4 is the same, only one line is left, and the remaining lines are deleted; where S5 is the same, only one line is left, and the remaining lines are deleted

What do you mean
Reply

Use magic Report

1

Threads

13

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-3-2 14:30:02
| Show all posts
The algorithm is roughly:

filelist: = TStringList.create;
filelist.loadfromfile (...);
newlist: = TStringList.Create;
s4list: = TStringList.Create;
s4list.sorted: = True; // sorting will speed up the search

for i: = 0 to filelist.count -1
begin
   // Separate a line of text file, extract s4,
.......

  if newlist.indexof (s4) <0 then
begin
  newlist.add (filelist [i]);
  s4list.add (s4);
end;
end;

newlist.savetofile (....)
Reply

Use magic Report

1

Threads

13

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-3-2 16:15:02
| Show all posts
The above is to delete S4, S5 is similar
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