Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
psammy007 authored May 25, 2020
1 parent 972205a commit 24369ce
Show file tree
Hide file tree
Showing 94 changed files with 4,523 additions and 0 deletions.
39 changes: 39 additions & 0 deletions 3dSurfaceArea.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include<stdio.h>

int area(int a[][100],int h,int w)
{
int i,j,temp;
int totalArea = 0;
totalArea = 2 * (h * w);
for(i=0;i<h;i++)
totalArea += (a[i][0] + a[i][w-1]);
for(i=0;i<w;i++)
totalArea += (a[0][i] + a[h-1][i]);
for(i=0;i<h;i++){
for(j=1;j<w;j++){
temp = a[i][j] - a[i][j-1];
if(temp<0)
temp *= -1;
totalArea += temp;
}
}
for(i=0;i<w;i++){
for(j=1;j<h;j++){
temp = a[j][i] - a[j-1][i];
if(temp<0)
temp *= -1;
totalArea += temp;
}
}
return totalArea;
}

int main(){
int i,j,h,w,a[100][100];
scanf("%d%d",&h,&w);
for(i=0;i<h;i++)
for(j=0;j<w;j++)
scanf("%d",&a[i][j]);
printf("%d",area(a,h,w));
}

31 changes: 31 additions & 0 deletions acmicpc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include<stdio.h>

int main()
{
int n,m,i,j,k,res=0,t=0,c=0;
char str[500][500];
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
scanf("%s",str[i]);
for(i=0;i<n;i++)
for(j=0;j<m;j++)
str[i][j] = str[i][j] - 48;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
t=0;
for(k=0;k<m;k++)
t += str[i][k]|str[j][k];
if(t==res)
c++;
if(t>res)
{
res = t;
c = 0;
}
}
}
printf("%d\n%d",res,c+1);
}

21 changes: 21 additions & 0 deletions altChar.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<stdio.h>
#include<string.h>

int main()
{
int q,l,i,res;
char str[100000];
scanf("%d",&q);
while(q)
{
res = 0;
scanf("%s",str);
l = strlen(str);
for(i=1;i<l;i++)
if(str[i-1]==str[i])
res++;
printf("%d\n",res);
q--;
}
}

44 changes: 44 additions & 0 deletions anagram.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include<stdio.h>
#include<string.h>

int find(char str[],int l)
{
int i,j,h = l/2,sum=0;
int a[26]={0},b[26]={0};
for(i=0;i<h;i++)
{
++a[str[i]-'a'];
}
for(i=h;i<l;i++)
{
++b[str[i]-'a'];
}
for(i=0;i<26;i++)
{
a[i] = a[i] - b[i];
if(a[i]<0)
a[i] *= -1;
sum += a[i];
}
sum /= 2;
return sum;
}

int main()
{
int q,l,res;
char str[10000];
scanf("%d",&q);
while(q)
{
scanf("%s",str);
l = strlen(str);
if(l%2==1)
res = -1;
else
res = find(str,l);
printf("%d\n",res);
--q;
}
}

50 changes: 50 additions & 0 deletions angryProfessor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include<stdio.h>
struct node
{
int n,k;
int s[1000];

};

main()
{
struct node a[100];
int t,i=0,e=0,d,c;
scanf("%d",&t);
while(i<t)
{
int j=0;
scanf("%d",&a[i].n);
int m=a[i].n;
scanf("%d",&a[i].k);
while(j<m)
{
scanf("%d",&a[i].s[j]);
j++;
}
i++;
}
while(e<t)
{
int count=0;
c=0;d=0;
while(d<a[e].n)
{
if(a[e].s[c]<=0)
{
count++;
}
c++;
d++;
}
// printf("count=%d\n",count);
//printf("k=%d\n",a[e].k);
if(count>=a[e].k)
printf("NO\n");
else
printf("YES\n");
e++;
//printf("e=%d\n",e);
}

}
67 changes: 67 additions & 0 deletions appendDelete.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

main()
{
char a[100],b[100];
int n,count=0;
scanf("%s",a);
scanf("%s",b);
scanf("%d",&n);
int j=0,l,k,x=0,y=0;
l=strlen(a);
k=strlen(b);
if(l-k==n || k-l==n)
{
printf("Yes\n");
exit(0);
}
while(j<l || j<k)
{
if(a[j]!=b[j])
break;
j++;
}
int z=j;
int f=j;
while(j<l)
{
x++;
j++;
}
while(f<k)
{
y++;
f++;
}
int sum;
sum=x+y;
//printf("%d\n",sum);
if(sum==n)
printf("Yes\n");
else if(sum>n)
printf("No");
else
{
if((n-sum)%2==0)
printf("Yes\n");
else
{
if(sum+((z*2)+1)==n)
printf("Yes");
else
{
if(z==0)
{
if((n-k*2)%2==1)
printf("Yes");
}
else
printf("No");
}
}

}

}
28 changes: 28 additions & 0 deletions appleOrange.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include<stdio.h>

main()
{
int s,t,a,b,m,n,p[100000],q[100000],i=0,k=0,apple=0,orange=0;
scanf("%d %d",&s,&t);
scanf("%d %d",&a,&b);
scanf("%d %d",&m,&n);
while(i<m)
{
scanf("%d",&p[i]);
if((p[i]+a)>=s && (p[i]+a)<=t)
{
apple++;
}
i++;
}
while(k<n)
{
scanf("%d",&q[k]);
if((q[k]+b)>=s && (q[k]+b)<=t)
{
orange++;
}
k++;
}
printf("%d\n%d",apple,orange);
}
33 changes: 33 additions & 0 deletions arrayLeftshift.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<stdio.h>

void reverseArray(int arr[],int s,int e){
int temp;
while(s<e){
temp = arr[s];
arr[s] = arr[e];
arr[e] = temp;
s++;
e--;
}
}

void shiftArray(int arr[],int n,int s){
reverseArray(arr,0,s-1);
reverseArray(arr,s,n-1);
reverseArray(arr,0,n-1);
}

void print(int arr[],int n){
int i;
for(i=0;i<n;i++)
printf("%d ",arr[i]);
}

int main(){
int i,n,s,arr[100000];
scanf("%d%d",&n,&s);
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
shiftArray(arr,n,s);
print(arr,n);
}
29 changes: 29 additions & 0 deletions arrayReversal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>

int main()
{
int num, *arr, i;
scanf("%d", &num);
arr = (int*) malloc(num * sizeof(int));
for(i = 0; i < num; i++) {
scanf("%d", arr + i);
}
/* Write the logic to reverse the array. */
int r=num-1;i=0;
int temp;
while(i<r)
{
temp=arr[i];
arr[i]=arr[r];
arr[r]=temp;
i++;r--;

}

for(i = 0; i < num; i++)
printf("%d ", *(arr + i));
return 0;
}


33 changes: 33 additions & 0 deletions arrayRightshift.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<stdio.h>

void reverseArray(int arr[],int s,int e){
int temp;
while(s<e){
temp = arr[s];
arr[s] = arr[e];
arr[e] = temp;
s++;
e--;
}
}

void shiftArray(int arr[],int n,int s){
reverseArray(arr,0,n-s-1);
reverseArray(arr,n-s,n-1);
reverseArray(arr,0,n-1);
}

void print(int arr[],int n){
int i;
for(i=0;i<n;i++)
printf("%d ",arr[i]);
}

int main(){
int i,n,s,arr[100000];
scanf("%d%d",&n,&s);
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
shiftArray(arr,n,s);
print(arr,n);
}
Loading

0 comments on commit 24369ce

Please sign in to comment.