Codechef : December Challenge Division 3 Solutions
Problem 1 - Utkarsh and Placement - UTKPLC
- #include <iostream>
- using namespace std;
- int main() {
- int t;
- cin>>t;
- while(t--)
- {
- char a,b,c,e,f;
- cin>>a>>b>>c>>e>>f;
- int lp1 = 0;
- int lp2 = 0;
- if(e==a){
- lp1=3;
- }
- else if(e==b){
- lp1 =2;
- }else{
- lp1=1;
- }
- if(f==a){
- lp2=3;
- }else if(f==b){
- lp2=2;
- }else{
- lp2=1;
- }
- if(lp1>lp2)
- {
- cout<<e<<endl;
- }
- else{
- cout<<f<<endl;
- }
- }
- return 0;
- }
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- int n;
- cin>>n;
- int a[n];
- for(int i = 0; i < n; i++)
- {
- cin>>a[i];
- }
- int mx = 1;
- int c = 1;
- sort(a,a+n);
- for(int i = 1; i < n; i++)
- {
- if(a[i] == a[i-1])
- {
- c++;
- mx = max(mx, c);
- }
- else{
- c=1;
- }
- }
- if(n==mx){
- cout<<0<<endl;
- continue;
- }
- if(mx==1){
- cout<<-1<<endl;
- continue;
- }
- cout<<(n-mx)+1<<endl;
- }
- return 0;
- }
Problem 3 - Valleys and Hills - VANDH
- #include<bits/stdc++.h>using namespace std;int main(){int t; cin>>t;while(t--){int n,m;cin>>n>>m;string ans = "";if(m==n){for(int i=0;i<n+1;i++) ans+="01";}else if(m>n){for(int i=0;i<n+1;i++) ans+="10";for(int i=0;i<m-n-1;i++) ans+="110";ans+="1";}else{for(int i=0;i<m;i++) ans+="01";for(int i=0;i<n-m;i++) ans+="010";}cout<<ans.size()<<endl;cout<<ans<<endl;}return 0;}
Problem 4 - Check Mate - CHECKMATE
- #include <iostream>#include<cmath>using namespace std;int main() {int t;cin>>t;while(t--){int xk,yk,x1,y1,x2,y2;cin>>xk>>yk>>x1>>y1>>x2>>y2;string ans="NO";if(!(xk==1 || xk==8 || yk==1 || yk==8)) ans="NO";else{if(xk==1)if((x1==2 || x2==2 )&& y1!=y2)if(abs(y1-yk) > 1 && abs(y2-yk)>1) ans="YES";else if(xk==8)if((x1==7 || x2==7) && y1!=y2)if(abs(y1-yk) > 1 && abs(y2-yk)>1) ans="YES";if(yk==1)if((y1==2 || y2==2) && x1!=x2)if(abs(x1-xk) > 1 && abs(x2-xk)>1) ans="YES";else if(yk==8)if((y1==7 || y2==7) && x1!=x2)if(abs(x1-xk) > 1 && abs(x2-xk)>1) ans="YES";}cout<<ans<<endl;}return 0;}
Problem 5 - Rock Paper Scissors - ROPASCI
Problem 6 - Squares Counting - GRIDSQRS
Note : Come here often soon all solutions will be available
Request : Please click any of the 3 Ads shown on your screen and let them load, your 30 seconds are so valuable for someone you don't know 🥺