1380B - Universal Solution - CodeForces Solution


greedy *1400

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h> 
#include<iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set2;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set_s;
typedef tree<pair<int,int>,null_type,less_equal<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set_s2;
typedef long long int ll; 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pi      2*acos(0.0) 
#define vll     vector<ll> 
#define pq_      priority_queue 
#define pq_min  <int,vector<int>,greater<int>> 
#define pq_max  <int> 
#define vi      vector<int> 
#define vii     vector<pair<int, int>> 
#define pii     pair<int, int> 
#define pb      push_back 
#define sp      ' ' 
#define sz(n)   (int)n.size() 
#define all(n)  n.begin(),n.end() 
#define rall(n) n.rbegin(), n.rend()
#define YES     cout<<"YES\n"; 
#define yes     cout<<"yes\n"; 
#define NO      cout<<"NO\n"; 
#define no      cout<<"no\n"; 
#define bye     return 0; 
const double    eps = 1e-9;
const int       MAX = 1e5; 
const int 		lim = 1e6; 
bool odd(ll num) { return ((num & 1) == 1);}
bool even(ll num) { return ((num & 1) == 0);}
bool isEqual(double a,double b) {return abs(a-b)<eps;}
bool isGreater(double a,double b) {return a>=b+eps;} 
bool isGreaterEqual(double a,double b) {return a>b-eps;}
#define tc int t;cin >> t;while (t--) 
#define mset(n, v) memset(n, v, sizeof(n))
#define chk(n) for(auto it:n)
#define ff(i,n) for(int i = 0; i < n; i++)
#define ff1(i,n) for(int i = 1; i <= n; i++)
#define lcm(a, b) (((a) * (b)) / __gcd(a, b))
int dx[8] = {1,-1, 0, 0, 1, -1, -1, 1}; 
int dy[8] = {0, 0, 1,-1, 1, -1, 1, -1};
bool comp(pair<ll,ll> x,pair<ll,ll> y)
{
    ll p = x.first+x.second;
    ll q = y.first+y.second;
    if(p==q)
    {
        return x.first>y.first;
    }
    return x.first+x.second<y.first+y.second;
}
int main()  
{ 
    fast
    tc
    {
        map<char,int>mp;
        string str;
        cin>>str;
        string x;
        ff(i,str.length())
        {
            mp[str[i]]++;
        }
        int mx=0;
        char ch;
        for(auto it:mp)
        {
            if(mx<it.second)
            {
                ch = it.first;
                mx = it.second;
            }
        }
        if(ch=='R')
        {
            ff(i,str.length())
            {
                str[i] = 'P';
            }
        }
        else if(ch=='S')
        {
            ff(i,str.length())
            {
                str[i] = 'R';
            }
        }
        else 
        {
            ff(i,str.length())
            {
                str[i] = 'S';
            }
        }
        cout<<str<<endl;
    }
    bye
}


Comments

Submit
0 Comments
More Questions

74. Search a 2D Matrix
71. Simplify Path
62. Unique Paths
50. Pow(x, n)
43. Multiply Strings
34. Find First and Last Position of Element in Sorted Array
33. Search in Rotated Sorted Array
17. Letter Combinations of a Phone Number
5. Longest Palindromic Substring
3. Longest Substring Without Repeating Characters
1312. Minimum Insertion Steps to Make a String Palindrome
1092. Shortest Common Supersequence
1044. Longest Duplicate Substring
1032. Stream of Characters
987. Vertical Order Traversal of a Binary Tree
952. Largest Component Size by Common Factor
212. Word Search II
174. Dungeon Game
127. Word Ladder
123. Best Time to Buy and Sell Stock III
85. Maximal Rectangle
84. Largest Rectangle in Histogram
60. Permutation Sequence
42. Trapping Rain Water
32. Longest Valid Parentheses
Cutting a material
Bubble Sort
Number of triangles
AND path in a binary tree
Factorial equations