Advertisement
Guest User

minuman

a guest
Feb 29th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include<string>
  3. using namespace std;
  4. void swap(int *xp, int *yp)
  5. {
  6. int temp = *xp;
  7. *xp = *yp;
  8. *yp = temp;
  9. }
  10. void swaps(string *xp, string *yp)
  11. {
  12. string temp = *xp;
  13. *xp = *yp;
  14. *yp = temp;
  15. }
  16. void bubbleSort(int arr[],string x[], int n)
  17. {
  18. int i, j;
  19. bool swapped;
  20. for (i = 0; i < n-1; i++)
  21. {
  22. swapped = false;
  23. for (j = 0; j < n-i-1; j++)
  24. {
  25. if (arr[j] > arr[j+1])
  26. {
  27. swap(&arr[j], &arr[j+1]);
  28. swaps(&x[j], &x[j+1]);
  29. swapped = true;
  30. }
  31. }
  32.  
  33. if (swapped == false)
  34. break;
  35. }
  36. }
  37. int main()
  38. {
  39. string x[3003];
  40. int arr[1002];
  41. int n,o ;
  42. cin >> n;
  43. for(int i=0;i<n;i++)
  44. {
  45. cin >> arr[i]>>x[i];
  46. }
  47. o=0;
  48. bubbleSort(arr, x, n);
  49. for (int i=0;i<n-1;i++){
  50. for (int j=i+1;j<n;j++){
  51. for(int k=j+1;k<n;k++){
  52. string z="";
  53. z=x[i];
  54. if(z.find("A")<6 and z.find("B")<6 and z.find("C")<6){
  55. o=arr[i];
  56. break;
  57. }
  58. z=x[j];
  59. if(z.find("A")<6 and z.find("B")<6 and z.find("C")<6){
  60. o=arr[j];
  61. break;
  62. }
  63. z=x[k];
  64. if(z.find("A")<6 and z.find("B")<6 and z.find("C")<6){
  65. o=arr[k];
  66. break;
  67. }
  68. z=x[k]+x[j];
  69. if(z.find("A")<6 and z.find("B")<6 and z.find("C")<6){
  70. o=arr[j]+arr[k];
  71. break;
  72. }
  73. z=x[i]+x[j];
  74. if(z.find("A")<6 and z.find("B")<6 and z.find("C")<6){
  75. o=arr[i]+arr[j];
  76. break;
  77. }
  78. z=x[i]+x[j]+x[k];
  79. if(z.find("A")<6 and z.find("B")<6 and z.find("C")<6){
  80. o=arr[i]+arr[j]+arr[k];
  81. break;
  82. }
  83. }
  84. if(o>0){
  85. break;
  86. }
  87.  
  88. }
  89. if(o>0){
  90. break;
  91. }
  92. }
  93. if (o>0){
  94. cout << o <<endl;
  95. }else {
  96. cout <<"-1"<<endl;
  97. }
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement