Skip to content

Commit 224a84c

Browse files
committed
practice
1 parent 3c15ea8 commit 224a84c

19 files changed

+2582
-0
lines changed
+190
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
Institute: National Institute of Technology, Uttarakhand
5+
*/
6+
#include <bits/stdc++.h>
7+
#include <ext/pb_ds/assoc_container.hpp>
8+
#include <ext/pb_ds/tree_policy.hpp>
9+
using namespace std;
10+
using namespace __gnu_pbds;
11+
typedef long long ll ;
12+
typedef unsigned long long ull;
13+
typedef vector<ll> vl;
14+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
15+
/* Abbrevations */
16+
#define ff first
17+
#define ss second
18+
#define mp make_pair
19+
#define line cout<<endl;
20+
#define pb push_back
21+
#define Endl "\n"
22+
// loops
23+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
24+
// Some print
25+
#define no cout<<"NO"<<endl;
26+
#define yes cout<<"YES"<<endl;
27+
// sort
28+
#define all(V) (V).begin(),(V).end()
29+
#define srt(V) sort(all(V))
30+
#define srtGreat(V) sort(all(V),greater<ll>())
31+
// some extra
32+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
33+
#define precision(x) cout<<fixed<<setprecision(x);
34+
#define sz(V) ll(V.size())
35+
// template
36+
template <typename T>
37+
T mymax(T x,T y)
38+
{
39+
return (x>y)?x:y;
40+
}
41+
// function
42+
ll power(ll x,ll y,ll mod)
43+
{
44+
ll res=1;
45+
// x=x%mod;
46+
while(y>0)
47+
{
48+
if(y%2==1)
49+
{
50+
res*=x;
51+
// res=res%mod;
52+
}
53+
y/=2; x*=x; // x=x%mod;
54+
}
55+
return res;
56+
}
57+
ll str_to_num(string s)
58+
{
59+
stringstream pk(s);
60+
ll num;
61+
pk>>num;
62+
return num;
63+
}
64+
65+
string num_to_str(ll num)
66+
{
67+
return to_string(num);
68+
}
69+
// datatype definination
70+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
71+
class Point
72+
{
73+
public:
74+
ll x;
75+
ll y;
76+
ll z;
77+
ll getsum()
78+
{
79+
return x+y+z;
80+
}
81+
};
82+
/* ascii value
83+
A=65,Z=90,a=97,z=122
84+
*/
85+
/* --------------------MAIN PROGRAM----------------------------*/
86+
// to run ctrl+b
87+
const ll INF=LONG_MAX;
88+
89+
90+
ll solve()
91+
{
92+
string s;
93+
cin>>s;
94+
ll n=sz(s);
95+
ll upper=0,lower=0,num=0;
96+
for(auto x:s){
97+
if(x>='A'&&x<='Z')
98+
upper++;
99+
else if(x>='a'&&x<='z')
100+
lower++;
101+
else
102+
num++;
103+
}
104+
if(num==0&&lower==0){
105+
s[0]='a',s[1]='1';
106+
}
107+
else if(lower==0&&upper==0)
108+
s[0]='a',s[1]='A';
109+
else if(num==0&&upper==0)
110+
s[0]='1',s[1]='A';
111+
else if(num==0){
112+
if(upper>1){
113+
for(ll i=0;i<n;i++){
114+
if(isupper(s[i])){
115+
s[i]='1';
116+
break;
117+
}
118+
}
119+
}
120+
else{
121+
for(ll i=0;i<n;i++){
122+
if(islower(s[i])){
123+
s[i]='1';
124+
break;
125+
}
126+
}
127+
}
128+
}
129+
else if(lower==0){
130+
if(upper>1){
131+
for(ll i=0;i<n;i++){
132+
if(isupper(s[i])){
133+
s[i]='a';
134+
break;
135+
}
136+
}
137+
}
138+
else{
139+
for(ll i=0;i<n;i++){
140+
if(isdigit(s[i])){
141+
s[i]='a';
142+
break;
143+
}
144+
}
145+
}
146+
}
147+
else if(upper==0){
148+
if(lower>1){
149+
for(ll i=0;i<n;i++){
150+
if(islower(s[i])){
151+
s[i]='A';
152+
break;
153+
}
154+
}
155+
}
156+
else{
157+
for(ll i=0;i<n;i++){
158+
if(isdigit(s[i])){
159+
s[i]='A';
160+
break;
161+
}
162+
}
163+
}
164+
}
165+
cout<<s<<endl;
166+
return 0;
167+
}
168+
169+
int main()
170+
{
171+
speed;
172+
/* #ifndef ONLINE_JUDGE
173+
freopen("input.txt","r",stdin);
174+
freopen("output.txt","w",stdout);
175+
#endif */
176+
ll TestCase=1;
177+
cin>>TestCase;
178+
while(TestCase--)
179+
{
180+
solve();
181+
}
182+
}
183+
/* -----------------END OF PROGRAM --------------------*/
184+
/*
185+
* stuff you should look before submission
186+
* constraint and time limit
187+
* int overflow
188+
* special test case (n=0||n=1||n=2)
189+
* don't get stuck on one approach if you get wrong answer
190+
*/

Codeforces/1245B-Restricted_RPS.cpp

+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
Institute: National Institute of Technology, Uttarakhand
5+
*/
6+
#include <bits/stdc++.h>
7+
#include <ext/pb_ds/assoc_container.hpp>
8+
#include <ext/pb_ds/tree_policy.hpp>
9+
using namespace std;
10+
using namespace __gnu_pbds;
11+
typedef long long ll ;
12+
typedef unsigned long long ull;
13+
typedef vector<ll> vl;
14+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
15+
/* Abbrevations */
16+
#define ff first
17+
#define ss second
18+
#define mp make_pair
19+
#define line cout<<endl;
20+
#define pb push_back
21+
#define Endl "\n"
22+
// loops
23+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
24+
// Some print
25+
#define no cout<<"NO"<<endl;
26+
#define yes cout<<"YES"<<endl;
27+
// sort
28+
#define all(V) (V).begin(),(V).end()
29+
#define srt(V) sort(all(V))
30+
#define srtGreat(V) sort(all(V),greater<ll>())
31+
// some extra
32+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
33+
#define precision(x) cout<<fixed<<setprecision(x);
34+
#define sz(V) ll(V.size())
35+
// template
36+
template <typename T>
37+
T mymax(T x,T y)
38+
{
39+
return (x>y)?x:y;
40+
}
41+
// function
42+
ll power(ll x,ll y,ll mod)
43+
{
44+
ll res=1;
45+
// x=x%mod;
46+
while(y>0)
47+
{
48+
if(y%2==1)
49+
{
50+
res*=x;
51+
// res=res%mod;
52+
}
53+
y/=2; x*=x; // x=x%mod;
54+
}
55+
return res;
56+
}
57+
ll str_to_num(string s)
58+
{
59+
stringstream pk(s);
60+
ll num;
61+
pk>>num;
62+
return num;
63+
}
64+
65+
string num_to_str(ll num)
66+
{
67+
return to_string(num);
68+
}
69+
// datatype definination
70+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
71+
class Point
72+
{
73+
public:
74+
ll x;
75+
ll y;
76+
ll z;
77+
ll getsum()
78+
{
79+
return x+y+z;
80+
}
81+
};
82+
/* ascii value
83+
A=65,Z=90,a=97,z=122
84+
*/
85+
/* --------------------MAIN PROGRAM----------------------------*/
86+
// to run ctrl+b
87+
const ll INF=LONG_MAX;
88+
89+
90+
ll solve()
91+
{
92+
ll n;
93+
cin>>n;
94+
ll a,b,c;
95+
cin>>a>>b>>c;
96+
map<char,ll> m;
97+
m['R']=a;
98+
m['P']=b;
99+
m['S']=c;
100+
string s,ans="";
101+
ll win=0,lose=0;
102+
cin>>s;
103+
for(auto x:s){
104+
if(x=='R'){
105+
if(m['P']>0){
106+
win++;
107+
m['P']--;
108+
b--;
109+
ans+='P';
110+
}
111+
else
112+
ans+='@';
113+
}
114+
else if(x=='P'){
115+
if(m['S']>0){
116+
c--;
117+
win++;
118+
m['S']--;
119+
ans+='S';
120+
}
121+
else
122+
ans+='@';
123+
}
124+
else if(x=='S'){
125+
if(m['R']>0){
126+
a--;
127+
win++;
128+
m['R']--;
129+
ans+='R';
130+
}
131+
else
132+
ans+='@';
133+
}
134+
}
135+
if(win>=((n+1)/2)){
136+
yes
137+
for(ll i=0;i<n;i++){
138+
if(ans[i]=='@'){
139+
if(a>0){
140+
a--;
141+
ans[i]='R';
142+
}
143+
else if(b>0){
144+
b--;
145+
ans[i]='P';
146+
}
147+
else{
148+
c--;
149+
ans[i]='S';
150+
}
151+
}
152+
}
153+
cout<<ans<<endl;
154+
}
155+
else
156+
no
157+
return 0;
158+
}
159+
160+
int main()
161+
{
162+
speed;
163+
/* #ifndef ONLINE_JUDGE
164+
freopen("input.txt","r",stdin);
165+
freopen("output.txt","w",stdout);
166+
#endif */
167+
ll TestCase=1;
168+
cin>>TestCase;
169+
while(TestCase--)
170+
{
171+
solve();
172+
}
173+
}
174+
/* -----------------END OF PROGRAM --------------------*/
175+
/*
176+
* stuff you should look before submission
177+
* constraint and time limit
178+
* int overflow
179+
* special test case (n=0||n=1||n=2)
180+
* don't get stuck on one approach if you get wrong answer
181+
*/

0 commit comments

Comments
 (0)