Skip to content

Commit d12ed02

Browse files
committed
CODECHEF PROBLEM
1 parent cb9f36d commit d12ed02

6 files changed

+247
-0
lines changed

CODECHEF/CODECHEF_ERROR.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//CodeChef Problem : Chef and FeedBack(Easy)
2+
//Problem Code : ERROR
3+
//Author : Piyush
4+
#include<stdio.h>
5+
int main()
6+
{
7+
int t,i,count;
8+
char str[100006];
9+
scanf("%d",&t);
10+
while(t--)
11+
{
12+
scanf("%s",str);
13+
count=0;
14+
for(i=0;str[i]!='\0';i++)
15+
{
16+
if((str[i]=='0' && str[i+1]=='1' && str[i+2]=='0') ||(str[i]=='1' && str[i+1]=='0' && str[i+2]=='1'))
17+
{
18+
count=1;
19+
break;
20+
}
21+
}
22+
if(count==1)
23+
printf("Good\n");
24+
else
25+
printf("Bad\n");
26+
}
27+
return 0;
28+
}

CODECHEF/CODECHEF_LAPIN.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//CodeChef Problems: Lapindromes (Easy)
2+
//Problem Code : LAPIN
3+
//Author : Piyush
4+
#include<stdio.h>
5+
#include<string.h>
6+
int main()
7+
{
8+
int t,l,l1,no[150],no1[150],i,count;
9+
char str[1002];
10+
scanf("%d",&t);
11+
while(t--)
12+
{
13+
scanf("%s",str);
14+
l=strlen(str);
15+
if(l%2!=0)
16+
l1=(l/2)+1;
17+
else
18+
l1=(l/2);
19+
for(i=97;i<=122;i++)
20+
{
21+
no[i]=0;
22+
no1[i]=0;
23+
}
24+
for(i=0;i<l/2;i++)
25+
{
26+
++no[str[i]];
27+
}
28+
for(i=l1;i<l;i++)
29+
{
30+
++no1[str[i]];
31+
}
32+
count=0;
33+
for(i=97;i<=122;i++)
34+
{
35+
if(no[i]!=no1[i])
36+
{
37+
count++;
38+
break;
39+
}
40+
}
41+
if(count!=0)
42+
printf("No\n");
43+
else
44+
printf("Yes\n");
45+
}
46+
return 0;
47+
}

CODECHEF/CODECHEF_LCOLLIS.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//CodeChef Problem : Collisions (Beginner)
2+
//Problem Code : LCOLLIS
3+
//Author : Piyush
4+
#include<stdio.h>
5+
int main()
6+
{
7+
int t,n,m,no[100],i,j,k,sum,count;
8+
scanf("%d",&t);
9+
while(t--)
10+
{
11+
scanf("%d%d",&n,&m);
12+
for(i=0;i<100;i++)
13+
{
14+
no[i]=0;
15+
}
16+
i=0;
17+
j=n;
18+
while(j--)
19+
{
20+
for(k=1;k<=m;k++)
21+
{
22+
scanf("%d",&no[i]);
23+
++i;
24+
}
25+
i+=10;
26+
}
27+
sum=0;
28+
for(i=0;i<n;i++)
29+
{
30+
count=0;
31+
for(j=i;j<100;j+=10)
32+
{
33+
if(no[j] == 1)
34+
count++;
35+
}
36+
if(count>0)
37+
sum+=sum+(count-1);
38+
39+
}
40+
printf("%d\n",sum);
41+
}
42+
return 0;
43+
}

CODECHEF/CODECHEF_LECANDY.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//CodeChef Problem : Little Elephant and Candy(Peer)
2+
//Problem Code : LECANDY
3+
//Author : Piyush
4+
#include<stdio.h>
5+
int main()
6+
{
7+
int t,n,c,no,i,sum;
8+
scanf("%d",&t);
9+
while(t--)
10+
{
11+
sum=0;
12+
scanf("%d%d",&n,&c);
13+
while(n--)
14+
{
15+
scanf("%d",&no);
16+
c=c-no;
17+
}
18+
if(c>=0)
19+
printf("Yes\n");
20+
else
21+
printf("No\n");
22+
}
23+
return 0;
24+
}

CODECHEF/CODECHEF_MXMEDIAN.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//CodeChef Problem : Median of adjacent (MAY17)
2+
//Problem Code : MXMEDIAN
3+
//Author : Piyush
4+
#include<stdio.h>
5+
void swap(int [],int,int);
6+
int main()
7+
{
8+
int t,n,no[100001],i,j,temp;
9+
scanf("%d",&t);
10+
while(t--)
11+
{
12+
scanf("%d",&n);
13+
for(i=1;i<2*n+1;i++)
14+
{
15+
scanf("%d",&no[i]);
16+
}
17+
for(i=1;i<2*n;i++)
18+
{
19+
for(j=i+1;j<2*n+1;j++)
20+
{
21+
if(no[i]>no[j])
22+
{
23+
temp=no[i];
24+
no[i]=no[j];
25+
no[j]=temp;
26+
}
27+
}
28+
}
29+
printf("%d\n",no[n+n/2+1]);
30+
swap(no,2,n+1);
31+
for(i=1;i<2*n+1;i++)
32+
{
33+
printf("%d ",no[i]);
34+
}
35+
printf("\n");
36+
}
37+
return 0;
38+
}
39+
void swap(int no[],int l,int h)
40+
{
41+
int ne=h,tmp;
42+
while(l<ne)
43+
{
44+
tmp=no[l];
45+
no[l]=no[h];
46+
no[h]=tmp;
47+
l+=2;
48+
h++;
49+
}
50+
if(l<h)
51+
swap(no,l,h);
52+
}

CODECHEF/CODECHEF_VOTERS.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//CodeChef Problem : Disprepancies in the Voter List (Easy)
2+
//Problem Code : VOTERS
3+
//Author : Piyush
4+
#include<stdio.h>
5+
int main()
6+
{
7+
int n1,n2,n3,no[50000]={0},i,s,l,n,count;
8+
scanf("%d%d%d",&n1,&n2,&n3);
9+
count=0;
10+
scanf("%d",&n);
11+
s=n;
12+
l=n;
13+
for(i=2;i<=n1;i++)
14+
{
15+
scanf("%d",&n);
16+
if(n>l)
17+
l=n;
18+
if(n<s)
19+
s=n;
20+
++no[n-1];
21+
}
22+
for(i=1;i<=n2;i++)
23+
{
24+
scanf("%d",&n);
25+
if(n>l)
26+
l=n;
27+
if(n<s)
28+
s=n;
29+
++no[n-1];
30+
}
31+
for(i=1;i<=n3;i++)
32+
{
33+
scanf("%d",&n);
34+
if(n>l)
35+
l=n;
36+
if(n<s)
37+
s=n;
38+
++no[n-1];
39+
}
40+
for(i=s-1;i<=l-1;i++)
41+
{
42+
if(no[i]>=2)
43+
count++;
44+
}
45+
printf("%d\n",count);
46+
for(i=s-1;i<=l-1;i++)
47+
{
48+
if(no[i]>=2)
49+
printf("%d\n",i+1);
50+
}
51+
printf("\n");
52+
return 0;
53+
}

0 commit comments

Comments
 (0)