Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _2024
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string S = Console.ReadLine();
  14. int K = int.Parse(Console.ReadLine());
  15. char[] color = S.ToCharArray();
  16. int N = color.Length;
  17. int[] a = new int[N];
  18. for (int i = 0; i < N; i++)
  19. {
  20. a[i] = 1;
  21. {
  22. for (int j = 0; j < N; j++)
  23. if (i != j)
  24. if (color[i] == color[j])
  25. {
  26. a[i]++; a[j] = 0;
  27. }
  28. }
  29. }
  30. rep(ref a); int l1, l2, n;
  31. l1 = 0; n = 0;
  32. for (int i = 0; i < K ; i++)
  33. {
  34. if (a[i] == 0) break;
  35. l1 += a[i];
  36. }
  37.  
  38. if (K > N) l2 = 1;
  39. else
  40. {
  41. for (int i = K - 1; i < N; i++)
  42. {
  43. if (a[K - 1] == a[i]) n++;
  44. else break;
  45. }
  46. if (n-K>=0)
  47. l2 = Fact(n) / (Fact(K) * Fact(n - K));
  48. else l2 = 1;
  49. }
  50. Console.WriteLine(l1 + " " + l2);
  51. Console.ReadKey();
  52. }
  53.  
  54. static void rep(ref int[] a)
  55. {
  56. int x, i, j;
  57. int N = a.Length;
  58. for (i = 0; i < N; i++)
  59. {
  60. x = a[i];
  61. for (j = i - 1; j >= 0 && x > a[j]; j--)
  62. {
  63. a[j + 1] = a[j];
  64. }
  65. a[j + 1] = x;
  66. }
  67. }
  68.  
  69. static int Fact(int n)
  70. {
  71. if (n == 0 || n == 1)
  72. return 1;
  73. else return n * Fact(n - 1);
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement