Advertisement
Guest User

c#

a guest
Dec 11th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8. class Program
  9. {
  10. static int countDigits(int n)
  11. {
  12. int c = 0;
  13. while (n != 0)
  14. {
  15. c++;
  16. n /= 10;
  17. }
  18. return c;
  19. }
  20. static void Main(string[] args)
  21. {
  22. int n = int.Parse(Console.ReadLine());
  23. Console.WriteLine("--------------------\n");
  24. if (n == 2)
  25. Q2();
  26. else if (n == 3)
  27. Q3();
  28. else if (n == 4)
  29. Q4();
  30. }
  31. static void Q2()
  32. {
  33. int max = 0, maxN = 0;
  34. for (int i = 1; i <= 10; i++)
  35. {
  36. int n = int.Parse(Console.ReadLine()), temp = n;
  37. while (n != 0)
  38. {
  39. if (n % 100 > max)
  40. {
  41. max = n % 100;
  42. maxN = temp;
  43. }
  44. n /= 10;
  45. }
  46. }
  47. Console.WriteLine(maxN);
  48. }
  49. static void Q3()
  50. {
  51. int a = int.Parse(Console.ReadLine());
  52. int b = int.Parse(Console.ReadLine());
  53. while (!(a == -1 && b == -1))
  54. {
  55. int c = countDigits(b);
  56. Console.WriteLine(a * Math.Pow(10, c) + b);
  57. a = int.Parse(Console.ReadLine());
  58. b = int.Parse(Console.ReadLine());
  59. }
  60. }
  61. static void Q4()
  62. {
  63. int a = int.Parse(Console.ReadLine());
  64. int b = int.Parse(Console.ReadLine());
  65. bool finalFlag = true;
  66. while (b != 0)
  67. {
  68. int tempA = a;
  69. bool digitFlag = false;
  70. while (tempA != 0)
  71. {
  72. if (b % 10 == tempA % 10)
  73. digitFlag = true;
  74. tempA /= 10;
  75. }
  76. if (!digitFlag)
  77. finalFlag = false;
  78. b /= 10;
  79. }
  80. Console.WriteLine(finalFlag);
  81. }
  82.  
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement