Showing posts with label logical c programs. Show all posts
Showing posts with label logical c programs. Show all posts

Constellation - CodeVita 9 | Zonal Round

Constellation 

 Three characters { #, *, . } represents a constellation of stars and galaxies in space. Each galaxy is demarcated by # characters. There can be one or many stars in a given galaxy. Stars can only be in shape of vowels { A, E, I, O, U } . A collection of * in the shape of the vowels is a star. A star is contained in a 3x3 block. Stars cannot be overlapping. The dot(.) character denotes empty space. 

 Given 3xN matrix comprising of { #, *, . } character, find the galaxy and stars within them. 

 Note: Please pay attention to how vowel A is denoted in a 3x3 block in the examples section below. 

 Constraints 

 3 <= N <= 10^5 

 Input

 Input consists of single integer N denoting number of columns. 

 Output 

 Output contains vowels (stars) in order of their occurrence within the given galaxy. Galaxy itself is represented by # character. 

Example 1:

Input:

18

* . * # * * * # * * * # * * * . * .

* . * # * . * # . * . # * * * * * *

* * * # * * * # * * * # * * * * . *

Output: 

U#O#I#EA

Example 2:

Input:

12

* . * # . * * * # . * .

* . * # . . * . # * * *

* * * # . * * * # * . *
Output:

U#I#A

Program:

#include <stdio.h>
int main()
{
  int n,x1,y1;
  scanf("%d",&n);
  char x[3][n];
  for(int i=0;i<3;i++)
{
    for(int j=0;j<n;j++)
{
      scanf("%s",&x[i][j]);
    }
  }
  for(int i=0;i<n;i++)
  {
    if(x[0][i]=='#' && x[1][i]=='#' && x[2][i]=='#')
{
      printf("#");
    }
else if(x[0][i]=='.' && x[1][i]=='.' && x[2][i]=='.')
{}
else
{
      char a,b,c,a1,b1,c1,a2,b2,c2;
      x1 = i;
      a = x[0][x1];
      b = x[0][x1+1];
      c = x[0][x1+2];
      a1 = x[1][x1];
      b1 = x[1][x1+1];
      c1 = x[1][x1+2];
      a2 = x[2][x1];
      b2 = x[2][x1+1];
      c2 = x[2][x1+2];
      if(a=='.' && b=='*' && c=='.' && a1=='*' && b1=='*' && c1=='*' && a2=='*' && b2=='.' && c2=='*')
  { 
      printf("A");
        i = i + 2;
      }
      if(a=='*' && b=='*' && c=='*' && a1=='*' && b1=='*' && c1=='*' && a2=='*' && b2=='*' && c2=='*')
  { 
        printf("E");
        i = i + 2;
      }
      if(a=='*' && b=='*' && c=='*' && a1=='.' && b1=='*' && c1=='.' && a2=='*' && b2=='*' && c2=='*')
  { 
        printf("I");
        i = i + 2;
      }
      if(a=='*' && b=='*' && c=='*' && a1=='*' && b1=='.' && c1=='*' && a2=='*' && b2=='*' && c2=='*')
  { 
        printf("O");
        i = i + 2;
      }
      if(a=='*' && b=='.' && c=='*' && a1=='*' && b1=='.' && c1=='*' && a2=='*' && b2=='*' && c2=='*')
  { 
          printf("U");
        i = i + 2;
      }
    }
  }

}

You can also run it on an online IDE:    

Your feedback are always welcome! If you have any doubt you can contact me or leave a comment!  Happy Coding !! Cheers!!!

Related Links:

Codu And Sum Love 2018

Codu And Sum Love

Problem Description

```
Scanner sc = new Scanner(System.in);
long sum = 0;
int N = sc.nextInt();
for (int i = 0; i < N; i++) {
final long x = sc.nextLong(); // read input
String str = Long.toString((long) Math.pow(1 << 1, x));
str = str.length() > 2 ? str.substring(str.length() - 2) : str;
sum += Integer.parseInt(str);
}
System.out.println(sum%100);
```
Given N number of x’'s, perform logic equivalent of the above Java code and print the output

Constraints

 1<=N<=10^7 0<=x<=10^18

Input Format

 First line contains an integer N
Second line will contain N numbers delimited by space

Output

 Number that is the output of the given code by taking inputs as specified above
 

Explanation

Example 1
 
Input
 4 8 6 7 4
 Output
 64
Example 2
Input
3
1 2 3
Output
14

Program

#include <stdio.h>
long power(long k)
{
    long i,j=1;
    for(i=1;i<=k;i++)
        j=j*2;
        return j;
}
long length(long k)
{
    long ct=0,n1;
    while(k)
    {
        ct++;
        k=k/10;
    }
    return ct;
}
long reduce(long p1,long r1)
{
    long ct=0,k,cnt,rev=0,a[1000],h=0,i,sum1=0;
    while(p1)
    {
      k=p1%10;
      a[h]=k;
      h++;
      p1=p1/10;
     }
      for(i=1;i>=0;i--)
      sum1=sum1*10+a[i];
    return sum1;
}
int main() {
 long x,n,sum=0,r[70],p,c,f=0,i;
 scanf("%ld",&n);
 for(i=0;i<n;i++)
 {
    scanf("%ld",&x);
    p=power(x);
    c=length(p);
    if(c>2)
    {
    r[f++]=reduce(p,c);
    }
    else
    r[f++]=p;
 }
 for(i=0;i<n;i++)
 
 sum=sum+r[i];
   printf("%ld",(sum%100));
 
 
 return 0;
}

Output:

4 8 6 7 4
64


You can also try running it on online IDE: https://ide.geeksforgeeks.org/G3gXokhTbW

Your doubts and feedback are welcomed! you can comment it below Cheers!

Related Link: Super Ascii

Super Market Problem | TCS Code Vita 2023 - Zone 1 | Super Market TCS Code Vita 2023 Solution | Code Vita 2023 | Code Vita 2023 season 11 solution

 Problem Description: In a Super market we will find many variations of the same product. In the same way we can find many types of rice bag...