Skillrack Solutions VIT
Monday, 6 March 2017
Saturday, 11 February 2017
Thursday, 19 January 2017
Tuesday, 17 January 2017
Sunday, 6 November 2016
Skillrack Solutions VIT Bonus Practice Problem
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!
Skillrack Solutions VIT Practice Problem 8
Program 1 - Excess number
#include<stdio.h>
int main()
{
int n,s=0,c=0,*a,i,j;
scanf("%d",&n);
a=(int*)malloc(n*sizeof(n));
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
{
s=0;
c=0;
for(j=i+1;j<n;j++)
{
s+=a[j];
c++;
}
s=s/c;
if(a[i]>s)
printf("%d\n",a[i]);
}
printf("%d",a[n-1]);
}
Program 2 - Count of 2 digit prime numbers
#include<stdio.h>
#include<string.h>
int prime(int n)
{
int f=0,i;
for(i=2;i<=n/2;i++)
if(n%i==0)
{
f=1;
break;
}
return f;
}
int main()
{
char a[10];
int i,c=0,n,f;
scanf("%[^\n]",&a);
for(i=0;i<strlen(a)-1;i++)
{
n=((int)(a[i])-48)*10+(int)(a[i+1])-48;
if(prime(n)==0)
c++;
}
printf("%d",c);
}
Program 3 - Singular to Plural
#include<stdio.h>
#include<string.h>
int main()
{
char a[10];
int l;
scanf("%[^\n]",&a);
l=strlen(a);
if(a[l-1]=='y')
{
a[l-1]='\0';
strcat(a,"ies");
}
else if((a[l-1]=='s') || ((a[l-1]=='h')&&((a[l-2]=='c') || (a[l-2]=='s'))))
strcat(a,"es");
else
strcat(a,"s");
printf("%s",a);
}
Program 4 - Local Network
#include<stdio.h>
int main()
{
int n,i,j;
char a[5][20],b[5][8];
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s",&a[i]);
for(j=0;a[i][j-1]!='.';j++)
b[i][j]=a[i][j];
for(j=j;a[i][j]!='.';j++)
b[i][j]=a[i][j];
b[i][j]='\0';
}
for(i=0;i<n;i++)
printf("%s\n",b[i]);
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(strcmp(b[i],b[j])==0)
printf("Machines %d and %d are on the same local network",i+1,j+1);
}
Program 5 - L Shape
#include<stdio.h>
#include<stdlib.h>
int main()
{
int r,c,i,j,m,n;
char a[10][10];
scanf("%d%d",&r,&c);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf(" %c",&a[i][j]);
for(i=0;i<r-1;i++)
for(j=0;j<c-2;j++)
{
int c1=0,c2=0;
m=i;
while(a[m][j]==a[++m][j])
c1++;
n=j+1;
if(c1>0)
while(a[m-1][n]==a[m-1][++n])
c2++;
if((c1==c2)&&(c1!=0))
{
printf("Yes");
exit(0);
}
}
printf("No");
}
Try my app on play store and rate it!
Sunday, 25 September 2016
Skillrack Solutions VIT 1st October 2016
Program 1- Pangram
def pangram(s):
f=0
for i in range(97,123):
if s.count(chr(i))==0:
f=1
break
return f
s=input()
s=s.lower()
f=pangram(s)
if f==0:
print("Pangram")
else:
print("Not pangram")
Program 2- Adam number
def reverse(a):
b=0
while(a>0):
b=b*10+a%10
a=a//10
return b
a=int(input())
if a**2==(reverse(reverse(a)**2)):
print("Adam number")
else:
print("Not an Adam number")
Program 3- Automorphic number
n=int(input())
l=len(str(n))
sq=n**2
if n==sq%(10**l):
print("Automorphic")
else:
print("Not automorphic")
Program 4- Elizabeth walk
x=int(input())
y=int(input())
z=int(input())
m1=int(input())
m=0
m+=(x/1000)/3*60 + (y/1000)/2*60 + (z/1000)/6*60
m=int(m)
print(str(6+m//60)+" "+str(m%60))
m+=m1
m+=(x/1000)/3*60 + (y/1000)/6*60 + (z/1000)/2*60
m=int(m)
h=6+m//60
m=m%60
print(str(h)+" "+str(m))
Program 5- Isomorphic number
import sys
n=int(input())
a=[]
for i in range(n):
a.append(int(input()))
if len(str(a[0]))==1 or len(str(a[0]))==2:
print("No isomorphic")
sys.exit()
c=[]
for i in range(n):
a[i]=list(str(a[i]))
for i in range(len(a)):
c.append({})
for j in range(len(a[i])):
c[i].setdefault(a[i][j],[]).append(j)
print(''.join(a[0]))
for i in range(1,len(a)):
f=0
for j in c[i].values():
if j not in c[0].values():
f=1
break
if f==0:
print(''.join(a[i]))
Try my app on play store and rate it!
Subscribe to:
Posts (Atom)