Program 1 - Amicable number
m=int(input())
n=int(input())
s,f=0,0
for i in range(2,m//2+1):
if m%i==0:
s+=i
if s+1!=n:
f=1
if f==0:
s=0
for i in range(2,n//2+1):
if n%i==0:
s+=i
if s+1!=m:
f=1
if f==0:
print("Yes")
else:
print("No")
Program 2 - Deficient number
a=int(input())
s=0
for i in range(2,a//2+1):
if a%i==0:
s+=i
if s<a:
print("Deficient")
else:
print("Not deficient")
Program 3 - Kangaroo
s2=input()
s1=input()
f=0
for i in s1:
if i not in s2:
f=1
break
else:
s2=s2[s2.index(i)+1:]
if f==0:
print("True")
else:
print("False")
Program 4 - Path to max
n=int(input())
a=[]
for i in range(n):
a.append([])
for j in range(i+1):
a[i].append(int(input()))
s=0
for i in range(n):
s+=max(a[i])
print(s)
Program 5 - GMT to IST
import sys
d=input().rstrip()
h=int(input())
m=int(input())
day=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
if(d not in day) or (h<0 or h>24) or (m<0 or m>60):
print("Invalid input")
sys.exit()
m=m+30
if m>=60:
h+=6
m=m%60
else:
h+=5
if h>24:
print(day[day.index(d)+1])
print(str("%d\n"%(h-24))+" "+str("%d"%m))
else:
print(d)
print(str("%d\n"%h)+" "+str("%d"%m))
Program 6 - Palindrome or Symmetry
import math
def palindrome(s):
f=0
for i in range(len(s)//2):
if s[i]!=s[len(s)-i-1]:
f=1
break
return f
def symmetry(s):
f=0
for i in range(len(s)//2):
if s[i]!=s[math.ceil(len(s)/2)+i]:
f=1
break
return f
n=int(input())
s=[]
for i in range(n):
s.append(input().lower().rstrip())
for i in range(n):
f=palindrome(s[i])
f1=symmetry(s[i])
if f==0 and f1==0:
print("Both property")
elif f==0:
print("Palindrome")
elif f1==0:
print("Symmetry")
else:
print("No property")
Program 7 - Second smallest element
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,m,*a,i,j;
scanf("%d",&n);
a=(int*) malloc(n*sizeof(int));
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
for(j=0;j<n-i-1;j++)
if (a[j]>a[j+1])
{
m=a[j];
a[j]=a[j+1];
a[j+1]=m;
}
printf("%d",a[1]);
}
Program 8 - Cyclic Right shift
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,m,*a,i,j;
scanf("%d",&n);
a=(int*) malloc(n*sizeof(int));
for(i=0;i<n;i++)
scanf("%d",&a[i]);
scanf("%d",&m);
for(i=0;i<m;i++)
{
int t=a[n-1];
for(j=n-1;j>0;j--)
a[j]=a[j-1];
a[0]=t;
}
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}
Try my app on play store and rate it!
No comments:
Post a Comment