Starter 1 Contest Link
📌 Problem A:
printing format : (int)(string)(int) — Numerator/Denominator
Numerator= (6-maximum point between Yakko & Wakko+1)/gcd of 6 and (6-maximum point between Yakko & Wakko+1)
Denominator= 6/gcd of 6 and (6-maximum point between Yakko & Wakko+1)
Code in C++
//MSA
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int Y,W;
cin>>Y>>W;
int n1,n2,rem,k;
k = 6 - max(Y, W) + 1;
n1=k;
n2=6;
while(n2!=0)
{
rem=n1%n2;
n1=n2;
n2=rem;
}
cout<<k/n1<<"/"<<6/n1<<"\n";
return 0;
}
📌 Problem B:
Hint
Code in C++
//MSA
#include<bits/stdc++.h>
using namespace std;
int main()
{
int temp = 0,sz;
char ch[10000];
while(gets(ch)){
sz=strlen(ch);
for(int i=0;i<sz;i++){
if(ch[i]=='"'){
temp++;
if(temp%2!=0)
cout<<"``";
else
cout<<"''";
}
else
{
cout<<ch[i];
}
}
cout<<"\n";
}
return 0;
}
📌 Problem C:
(X == N || Y == M)»»»»»» divisa
1st Quadrant »»»»> NE: (X> N && Y> M) (+; +)
2nd Quadrant »»»»> NO: (X <N && Y> M) (-; +)
3rd Quadrant »»»»> SO: (X <N && Y <M) (-; -)
4th Quadrant »»»»> SE: (X> N && Y <M) (+; -)
Code in C++
//MSA
#include <bits/stdc++.h>
using namespace std;
int main ()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int k;
while (cin >> k)
{
if (k == 0)
break;
int N, M, X, Y;
cin >> N >> M;
for (int i = 1; i <= k; i ++)
{
cin >> X >> Y;
if (X == N || Y == M)
cout << "divisa\n";
else if (X <N && Y> M)
cout << "NO\n";
else if (X> N && Y> M)
cout << "NE\n";
else if (X> N && Y <M)
cout << "SE\n";
else if (X <N && Y <M)
cout << "SO\n";
}
}
return 0;
}
📌 Problem D:
we will only count the postive dust units , reason is given in the last line of the problem statement
Code in C++
//MSA
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
int casenumber=0;
for(int i=1;i<=t;i++)
{
int a,sum=0;
cin>>a;
for(int j=1;j<=a;j++)
{
int k;
cin>>k;
if(k>=0){
sum=sum+k;
}
}
casenumber=casenumber+1;
cout<<"Case "<<casenumber<<": "<<sum<<"\n";
}
return 0;
}
📌 Problem E:
input: Hypotenuse , Adjacent ,Opposite (random order)
output: using pythagorean theorem we have to check if it is a triangle or not
Code in C++
//MSA
#include<bits/stdc++.h>
using namespace std;
int main()
{
int k,a,b,c,i;
cin>>k;
for(i=1;i<=k;i++)
{
cin>>a>>b>>c;
if((a*a + b*b == c*c) || (a*a + c*c == b*b ) || (c*c + b*b == a*a) )
{
cout<<"Case "<<i<<": yes\n";
}
else
{
cout<<"Case "<<i<<": no\n";
}
}
return 0;
}
📌 Problem F:
if the string is equals to “donate” we have to add the amount to sum else we have to print the sum
Code in C++
//MSA
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,t,n;
string str;
int sum = 0;
cin >> t;
for (int i = 1; i <= t; i++) {
cin >> n;
sum = 0;
cout << "Case " << i <<":\n";
for (int i = 0; i < n; i++) {
cin >> str;
if(str == "donate") {
cin >> a;
sum=sum+ a;
}
else {
cout << sum <<"\n";
}
}
}
}
📌 Problem G:
time in seconds =abs(a-b)* 4+(3+5+3)+(a*4)+(5+3);
Code in C++
//MSA
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t,a,b,c=0,s,d;
cin>>t;
while(t--)
{
cin>>a>>b;
d = abs(a-b);
s=d*4+(3+5+3)+(a*4)+(5+3);
cout<<"Case "<<++c<<": "<<s<<"\n";
}
return 0;
}
📌 Problem H:
Each sonar(base=3,height=3)
the border cells are ignored
Minimum no of sonar=(row/base)*(col/height)
Code in C++
//MSA
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
for(int i=1;i<=t;i++)
{
int a,b;
cin>>a>>b;
cout<<(a/3)*(b/3)<<"\n";
}
return 0;
}
📌 Problem I:
taking a string as input and printing the exactly same input as output
Code in C++
//MSA
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
char str[10];
while(gets(str))
{
cout<<str<<"\n";
}
return 0;
}
📌 Problem J:
N= number of participants
B=budget
H= the number of hotels
W=the number of week
p=the price for one person staying the weekend at the hotel
a=the number of available beds for each weekend at the hotel
if sz=0 that means budget is low
if sz is more than 0 than we have to sort the array in ascending order and print the 1st index
Code in C++
//MSA
#include<bits/stdc++.h>
using namespace std;
int main()
{
int arr[1000],sz;
int N,B,H,W,a,p,cost;
while(cin>>N>>B>>H>>W)
{
sz=0;
for(int i=1; i<=H; i++)
{
cin>>p;
for(int j=1; j<=W; j++)
{
cin>>a;
if(a>=N)
{
cost=N*p;
if(cost<=B)
arr[sz++]=cost;
}
}
}
if(sz==0)
{
cout<<"stay home\n";
}
else
{
sort(arr,arr+sz);
cout<<arr[0]<<"\n";
}
}
return 0;
}