fork download
  1. using System;
  2. using System.Text;
  3.  
  4. public class Test
  5. {
  6. private static string FindLcs(string s, string t) {
  7. var L = new int[s.Length, t.Length];
  8. var z = 0;
  9. var ret = new StringBuilder();
  10. for (var i = 0 ; i != s.Length ; i++) {
  11. for (var j = 0 ; j != t.Length ; j++) {
  12. if (s[i] == t[j]) {
  13. if (i == 0 || j == 0) {
  14. L[i,j] = 1;
  15. } else {
  16. L[i,j] = L[i-1,j-1] + 1;
  17. }
  18. if (L[i,j] > z) {
  19. z = L[i,j];
  20. ret = new StringBuilder();
  21. }
  22. if (L[i,j] == z) {
  23. ret.Append(s.Substring( i-z+1, z));
  24. }
  25. } else {
  26. L[i,j]=0;
  27. }
  28. }
  29. }
  30. return ret.ToString();
  31. }
  32. private static string CutLcs(string s, string t) {
  33. for (;;) {
  34. var lcs = FindLcs(s, t);
  35. if (lcs.Length < 10) break;
  36. s = s.Replace(lcs, string.Format("[{0}]", lcs.Length));
  37. }
  38. return s;
  39. }
  40.  
  41. public static void Main()
  42. {
  43. string firstS = "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABQODxIPDRQSERIXFhQYHzMhHxwcHz8tLyUzSkFOTUlBSEZSXHZkUldvWEZIZoxob3p9hIWET2ORm4+AmnaBhH//2wBDARYXFx8bHzwhITx/VEhUf39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f3//";
  44. string secondS = "abcdefg2wBDABQODxIPDRQSERIXFh/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/abcdefg";
  45. Console.WriteLine(CutLcs(firstS, secondS));
  46. }
  47. }
Success #stdin #stdout 0.04s 37240KB
stdin
Standard input is empty
stdout
/9j/4AAQSkZJRgABAQEAYABgAAD/[22]QYHzMhHxwcHz8tLyUzSkFOTUlBSEZSXHZkUldvWEZIZoxob3p9hIWET2ORm4+AmnaBhH//2wBDARYXFx8bHzwhITx/VEhUf39[61]f3//