1567A - Domino Disaster - CodeForces Solution


Sorting *800

Please click on ads to support us..

Python Code:

class Solution:
    def find(self, string: str) -> str:
        another = ""
        
        for i in string:
            if i in "LR":
                another+= i
            else:
                if i == "U":
                    another+= "D"
                else:
                    another+= "U"
        return another

t = int(input())
for i in range(t):
    n = int(input())
    print(Solution().find(input()))
    

C++ Code:

#include<bits/stdc++.h>
using namespace std;
# define ll long long int
# define scan(arr,v,w) for(int i=v;i<w;i++) cin>>arr[i];
# define print(arr,v,w) for(int i=v;i<w;i++) cout<<arr[i]<<" ";
# define tc ll t;cin>>t;  while(t--)
# define fast ios::sync_with_stdio(0);cin.tie(0);
# define endl "\n"
 
int main(){
	fast;
//***********************************************************************************************************************************************************************************************
//dry run is necessary
//see corner cases 
tc{
int p;
cin>>p;
string s;
cin>>s;
for(int i=0;i<s.length();i++){
if(s[i]=='L' ||s[i]=='R'){
	cout<<s[i];
}else if(s[i]=='U'){

cout<<"D";
}else if(s[i]=='D'){

cout<<"U";
}

}
cout<<endl;	
}


//***********************************************************************************************************************************************************************************************
		return 0;	
}
 
 


Comments

Submit
0 Comments
More Questions

1631B - Fun with Even Subarrays
727A - Transformation from A to B
822B - Crossword solving
1623A - Robot Cleaner
884B - Japanese Crosswords Strike Back
862B - Mahmoud and Ehab and the bipartiteness
429A - Xor-tree
1675C - Detective Task
950A - Left-handers Right-handers and Ambidexters
672B - Different is Good
1C - Ancient Berland Circus
721A - One-dimensional Japanese Crossword
1715B - Beautiful Array
60B - Serial Time
453A - Little Pony and Expected Maximum
1715A - Crossmarket
1715C - Monoblock
1512C - A-B Palindrome
1679B - Stone Age Problem
402A - Nuts
792A - New Bus Route
221A - Little Elephant and Function
492C - Vanya and Exams
1369B - AccurateLee
892B - Wrath
999A - Mishka and Contest
727C - Guess the Array
1625C - Road Optimization
1715D - 2+ doors
267A - Subtractions