Advertisement
Imran1107048

A1: Consistency - Chapter 1

Aug 30th, 2021
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  5. #define int long long
  6. #define endl "\n"
  7. #define PI acos(-1.0)
  8. #define IN freopen("in.txt","r",stdin)
  9. #define OUT freopen("output.txt","w",stdout);
  10.  
  11. const int MOD = 1e9+7;
  12. const int INF = 2e5+5;
  13. const int N = 205;
  14.  
  15. void solve();
  16. int32_t main()
  17. {
  18. IOS;
  19. IN;
  20. OUT;
  21. cout << fixed << setprecision(10);
  22. int _ = 1;
  23. //cin >> _;
  24. while(_--) solve();
  25. return 0;
  26. }
  27.  
  28. void solve()
  29. {
  30. int lol;
  31. cin >> lol;
  32. for(int tt = 1;tt<=lol;tt++){
  33. cout << "Case #" << tt << ": ";
  34.  
  35. string s;
  36. cin >> s;
  37. int n = s.size();
  38. int a[26] = {0};
  39. for(int i=0;i<n;i++){
  40. a[s[i] - 'A']++;
  41. }
  42. vector<int>v, c;
  43. for(int i=0;i<26;i++){
  44. if(i==0 || i==4 || i==8 || i==14 || i==20){
  45. v.push_back(a[i]);
  46. }
  47. else{
  48. c.push_back(a[i]);
  49. }
  50. }
  51. sort(v.rbegin(), v.rend());
  52. sort(c.rbegin(), c.rend());
  53.  
  54. ///method-1
  55. vector<int>vv = v;
  56. vv[0] = 0;
  57. int cnt = 0;
  58. for(int i:vv){
  59. cnt += i;
  60. }
  61. cnt *= 2;
  62. for(int i:c)
  63. cnt += i;
  64.  
  65. ///method-2
  66. vector<int>vvv = c;
  67. vvv[0] = 0;
  68. int cntt = 0;
  69. for(int i:vvv){
  70. cntt += i;
  71. }
  72. cntt *= 2;
  73. for(int i:v)
  74. cntt += i;
  75.  
  76. cout << min(cnt, cntt) << endl;
  77. }
  78. }
  79.  
  80. ///Must see the constraints range
  81. ///Calculate the Time
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement