Day 24 of 100 day of code
It's day 24 and today I practiced three questions on codechef
#include <bits/stdc++.h>
using namespace std;
bool solve(int n){
int cnt =0;
int left_days = 120-n;
for(int i =0;i<n;i++){
char x;
cin>>x;
if(x=='1'){
cnt++;
}
}
int present = left_days+cnt;
float percent = float((present/120.0)*100);
return (percent>=75);
}
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
if(solve(n)){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
}
#include <bits/stdc++.h>
using namespace std;
int solve(int n){
int odd =0;
for(int i=0;i<n;i++){
int x;
cin>>x;
if(x%2==1){
odd++;
}
}
if(odd%2==0||n==1){
return 1;
}
return 2;
}
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int ans = solve(n);
cout<<ans<<endl;
}
}
#include <bits/stdc++.h>
using namespace std;
int solve(string s){
int n = s.size();
int cnt =0;
for(int i =0;i<n-1;i++){
if(s[i]=='<'&& s[i+1]=='>'){
cnt++;
}
}
return cnt;
}
int main(){
int t;
cin>>t;
while(t--){
string s;
cin>>s;
int ans = solve(s);
cout<<ans<<endl;
}
}
ย