Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using CodEx;
  6.  
  7. public class osek
  8. {
  9. public static string VyradPismena(string s, string t)
  10. {
  11. StringBuilder u = new StringBuilder(t);
  12. bool pravda = false;
  13. for (int i = 0; i < u.Length; i++)
  14. {
  15. for (int j = 0; j < s.Length; j++)
  16. {
  17. if (u[i] == s[j])
  18. {
  19. pravda = true;
  20. break;
  21. }
  22. }
  23. if (pravda == false)
  24. {
  25. u.Remove(i, 1);
  26. i--;
  27. }
  28. pravda = false;
  29.  
  30. }
  31. return u.ToString();
  32. }
  33. }
  34.  
  35. public class hledani
  36. {
  37. public static void rekurze(int i)
  38. {
  39. for (int j = program.x; j <= program.t.Length - 1; j = j + 1)
  40. {
  41. if (program.s[i] == program.t[j] && i < program.s.Length - 1 && j <= (program.t.Length - program.s.Length + i))
  42. {
  43. program.x = j + 1;
  44. rekurze(i + 1);
  45. }
  46. if (program.s[i] == program.t[j] && i == program.s.Length - 1)
  47. {
  48. program.pocet = program.pocet + 1;
  49. }
  50. }
  51. }
  52. }
  53. class program
  54. {
  55.  
  56. public static string s = "";
  57. public static string t = "";
  58. public static int pocet = 0;
  59. public static int x = 0;
  60. static void Main(string[] args)
  61. {
  62.  
  63. int i = 0;
  64. s = Console.ReadLine();
  65. int c = 0;
  66. string row;
  67. /*while ((row = Reader.Console().Line()) != null)
  68. {
  69. t += row;
  70. }
  71. while ((c = Console.Read()) != -1)
  72. {
  73. t += (char)c;
  74. }*/
  75. t = Console.ReadLine();
  76. DateTime ExecutionStartTime = DateTime.Now;
  77. osek.VyradPismena(s, t);
  78. DateTime ExecutionStopTime = DateTime.Now;
  79. TimeSpan rozdil = ExecutionStopTime - ExecutionStartTime;
  80. Console.WriteLine(rozdil.Seconds);
  81. ExecutionStartTime = DateTime.Now;
  82. hledani.rekurze(i);
  83. ExecutionStopTime = DateTime.Now;
  84. rozdil = ExecutionStopTime - ExecutionStartTime;
  85. Console.WriteLine(rozdil.Seconds);
  86. Console.WriteLine(pocet);
  87. Console.ReadLine();
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement