Responsive Ads Here
Showing posts with label codechef. Show all posts
Showing posts with label codechef. Show all posts

Sunday, 28 May 2017

Team Formation For Snackdown

problem id:--https://www.codechef.com/SNCKPA17/problems/TEAMFORM


code:--

#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
for(int i=1;i<=m;++i)
{
int num;
cin>>num>>num;
}
string ans[]={"yes","no"};
cout<<ans[n&1]<<'\n';
}
return 0;
}

Saturday, 27 May 2017

Prefix Inversions

problem id:--https://www.codechef.com/LTIME48/problems/PREFINVS


code:--

#include<iostream>
using namespace std;
int main()
{
string str;
cin>>str;
int l=str.length()-1,count=0;
char ch;
while(l>=0 && str[l]=='0')
{
--l;
}
if(l>=0)
do
{
if(str[l]=='0')
++count,ch=str[l];
else
++count,ch=str[l];
while(l>=0 && str[l]==ch)
{
--l;
}
}while(l>=0);
cout<<count<<'\n';
return 0;
}

Nothing in Common

problem id:--https://www.codechef.com/problems/NOTINCOM

code:--

#include<iostream>
#include<unordered_set>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
int num;
unordered_set<int> myset;
for(int i=1;i<=n;++i)
{
cin>>num;
myset.insert(num);
}
int count=0;
for(int i=1;i<=m;++i)
{
cin>>num;
if(myset.find(num)!=myset.end())
++count;
}
cout<<count<<'\n';
}
return 0;
}

Friday, 26 May 2017

Bond And Fond (codechef contest)

problem id:--https://www.codechef.com/LOCMAY17/problems/BONDFOND


code:--

#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
long long n,num,count=0,m,temp1,temp2,temp=1;
while(t--)
{
count=0;
cin>>n;
if((n&(n-1))==0)
{
cout<<0<<'\n';
continue;
}
num=n;
while(num)
{
++count;
num=num>>1;
}
temp1=n-(temp<<(count-1));
temp2=(temp<<count)-n;
m=temp1<temp2? temp1:temp2;
cout<<((temp1<temp2)? temp1:temp2)<<'\n';
}
return 0;

Wednesday, 24 May 2017

Snake Procession(codechef)

problem id:--https://www.codechef.com/SNCKQL17/problems/SNAKPROC

code:--


#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int l;
cin>>l;
string str;
cin>>str;
int i=0,flag=1;
string ans[]={"Invalid","Valid"};
while(str[i]!='\0')
{
if(str[i]!='.')
{
if(str[i]=='H' && flag==1)
flag=2;
else if(str[i]=='T' && flag==2)
flag=1;
else
{
flag=2;
break;
}
}
++i;
}
cout<<ans[(flag&1)]<<'\n';
}
return 0;
}