Saturday, 31 August 2019

I Love T code chef solution in C

Read sentences until user enters 0
for each sentence, if the first character in each word in the given sentence is vowel, append T and if it is not vowel replace that character by T. 
Also only first character in each word only must be capital letter.

Sample Input:
love apples
apples are gOOOd for HelatHH
0

Sample Output:
Tove Tapples
Tapples Tare Toood Tor Telathh



#include<stdio.h>
int isvowel(char ch)
{
    if(ch >='A' && ch <= 'Z')
        ch=ch+32;
    if(ch == 'a' ||ch == 'e'||ch == 'i'||ch == 'o'||ch == 'u')
        return 1;
    else
        return 0;
}

int main()
{
    char st[1000001];
    scanf("\n%[^\n]\n",st);
    while(st[0] != '0')
    {
        int i;
        for(i=0;st[i]!='\0';i++)
        {
        if(st[i] >= 'A' && st[i] <= 'Z')
                st[i]=st[i]+32;
        if(i == 0|| (st[i-1] == ' ' && st[i] != ' '))
        {
         
            if(isvowel(st[i]))
                printf("T%c",st[i]);
            else
                printf("T");
        }
        else
            printf("%c",st[i]);
        }
        printf("\n");
        scanf("\n%[^\n]\n",st);
    }
    return 0;
 
}

Monday, 26 August 2019

Migratory Birds Hacker Rank Solution in C

Problem:

https://www.hackerrank.com/challenges/migratory-birds/problem


#include <stdio.h> int main() { int n,i,max,ans; scanf("%d", &n); int a[n],h[6]={0}; for(i = 0; i < n; i++) { scanf("%d",&a[i]); h[a[i]]++; } max=h[1]; for(i = 2; i < 6; i++) { if(max<h[i]) { max=h[i]; ans=i; } } printf("%d",ans); return 0; }

Friday, 23 August 2019

Binary Numbers Hacker Rank Solution in C

 #include <stdio.h>
int main()
{
    int n,r,c=0,t=0;
    scanf("%d",&n);
    while(n>0)
    {
        r=n%2;
        if(r==1)
        {
            c++;
            if(c>t)
                t=c;
        }
        else
            c=0;
        n=n/2;
    }
    printf("%d",t);
    return 0;

}


Find Product Hacker Earth Solution in C,Let Us Understand Computer Hacker Earth Solution in C,Count Numbers Hacker Earth Solution in C

#include <stdio.h>
#define ma 1000000007
int main(){
int num,i,a;
unsigned long long int ans=1;
scanf("%d", &num);

for(i=0;i<num;i++){
   scanf("%d", &a);
   ans=(ans*a)%ma;
}
printf("%d", ans);

}

===============or=================
#include <stdio.h>
const int ma = 1e9+7;
int main(){
int num,i,a;
unsigned long long int ans=1;
scanf("%d", &num);

for(i=0;i<num;i++){
   scanf("%d", &a);
   ans=(ans*a)%ma;
}
printf("%d", ans);

}

=============================================================
Let Us Understand Computer Hacker Earth Solution in C

#include <stdio.h>
#include <math.h>
int main()
{
unsigned long long int t;
scanf("%llu",&t);
while(t--)
{
unsigned long long int k,n,ans,i;
scanf("%lld",&n);
i=1;
while(i<=sqrt(n))
{
i=i*2;
}
if(n/i>=i/2)
ans=n-n/i;
else
ans=(n-(i/2))+1;
  printf("%lld\n",ans);
}
}

===========Count Numbers Hacker Earth Solution in C==============
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. int main()
  4. {
  5. int t,i;
  6. scanf("%d",&t);
  7. for(i=1;i<=t;i++)
  8. {
  9. int n,j,c=0;
  10. scanf("%d",&n);
  11. n++;
  12. char s[n];
  13. scanf("%s",s);
  14. for(j=0;s[j]!='\0';j++)
  15. {
  16. if(isdigit(s[j]) && !isdigit(s[j-1]))
  17. c++;
  18. }
  19. printf("%d\n",c);
  20. }
  21. return 0;
  22. }

Thursday, 22 August 2019

Finalized without bounds infix to postfix

#include<stdio.h>
#include <process.h>
#define MAX 50
char stack[MAX];
int top=-1;
int getpriority(char);
void push(char);
char pop();
main()
{
char infix[50],temp,ch,postfix[50];
int i=0,j=0;
printf("enter the infix expression\n");
scanf("%s",&infix);
while(infix[i] != '\0')
{
ch=infix[i];
if(ch == '(')
push(ch);
else if(ch == ')')
{
while(stack[top]!='(')
postfix[j++]=pop();
temp=pop();// popping the (
}
else if(isdigit(ch)||isalpha(ch))
postfix[j++]=ch;
else
{
while(getpriority(stack[top])>=getpriority(ch))
postfix[j++]=pop();
push(ch);
}
i++;
}
while(top != -1)
postfix[j++]=pop();
postfix[j]='\0';
puts(postfix);
}
int getpriority(char ch)
{
if( ch == '*'|| ch == '/'|| ch == '%')
return 2;
else if(ch == '+' || ch == '-')
return 1;
else
return 0;
}
void push(char item)
{
if(top == MAX-1)
{
printf("stack is full");
return;
}
top=top+1;
stack[top]=item;
}

char pop()
{
if(top == -1)
{
printf("stack empty");
return;
}
char temp;
temp=stack[top];
top=top-1;
return temp;
}

Resize an image keeping Aspect Ratio using Python

import cv2
import numpy as np

img = cv2.imread('flower.jpg');
# To resize the image keeping aspect ratio
rows=100.0/img.shape[1] #img.shape[1] gives the number of rows
dimensions = (100, int(img.shape[0]*rows))
resized = cv2.resize(img, dimensions, interpolation = cv2.INTER_AREA)
cv2.imshow("Original", img)
cv2.imshow("Resized", resized)
cv2.waitKey(0)
cv2.destroyAllWindows


Output:





















Resized Image: