Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4.  
  5. namespace _9._Rage_Quit
  6. {
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. string [] words = new string [20000];
  12. short [] repeats = new short [20000];
  13. bool [] uniqueChars = new bool [130];
  14. StringBuilder input = new StringBuilder();
  15. short next=0;
  16. int index = 0;
  17. while (true)
  18. {
  19. short ch = (Int16)Console.Read();
  20. if (ch == 13) break;
  21. if (ch > 47 && ch < 58)
  22. {
  23. bool nextDigit = false;
  24. next = (Int16)Console.Read();
  25. if (next > 47 && next < 58) nextDigit = true;
  26. short rep = (nextDigit) ? (short)(((ch - 48) * 10) + next - 48) : (short)(ch - 48);
  27. if (rep > 0)
  28. {
  29. var word = input.ToString();
  30. words[index] = word;
  31. repeats[index] = rep;
  32. foreach (var letter in word)
  33. if (!uniqueChars[(int)letter]) uniqueChars[(int)letter] = true;
  34. }
  35. index++;
  36. input.Clear();
  37. if (next == 13) break;
  38. if (!nextDigit)
  39. {
  40. if (next > 96 && next < 123) next -= 32;
  41. input.Append((char)next);
  42. }
  43. }
  44. else
  45. {
  46. if (ch > 96 && ch < 123) ch -= 32;
  47. input.Append((char)ch);
  48. }
  49. }
  50. int count = 0;
  51. for (int i = 0; i < 130; i++) if (uniqueChars[i]) count++;
  52. Console.WriteLine($"Unique symbols used: {count}");
  53.  
  54. StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
  55. sw.AutoFlush = true;
  56. Console.SetOut(System.IO.TextWriter.Null);
  57.  
  58. for (int i=0; i< index; i++)
  59. {
  60. for (int j = 0; j < repeats[i]; j++) input.Append(words[i]);
  61. sw.Write(input);
  62. input.Clear();
  63. }
  64. // Console.SetOut(sw);
  65.  
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement