In: Computer Science
In Physics, Mathematics, and related fields, a wave is a disturbance of one of more fields such that the field values oscillate repeatedly about a stable equilibrium value. Waves are usually represented using mathematical functions of the form F (x, t), where x = position and t = time.
Your task is to write a program that will visualize a given wave for exactly N seconds. You do not need to worry about evaluating the mathematical function F(x,t), as the wave will be given to you using its sample representation.
The sample representation of a wave is a series of points that represents the result of the F(x,t) function at each given t. In this problem, you will be given N samples (one for each second) represented by N integers Yi, which represents the vertical coordinate of the wave at time i.
Format Input
The first line contains a single integer N, the number of seconds you need to visualize the wave for. The next line contains N integers Y1, Y2, · · · , Yn as described in the problem statement.
Format Output
Visualize the wave given in the input. The wave should be visualized using a rectangle N characters long and 9 characters tall. Coordinates where the wave is currently in should be represented using the # (hash) character whilst empty coordinates should be represented using the . (dot) character. For clarity, please refer to the sample output section.
Constraints
• 1 ≤ N ≤ 104 • 1≤Yi ≤9
Sample Input 1 (standard input)
9
1 2 3 4 5 6 7 8 9
Sample Output 1 (standard output)
........#
.......#.
......#..
.....#...
....#....
...#.....
..#......
.#.......
#........
JAVA VERSION:
import java.util.*;
public class Main
{
   public static void main(String[] args) {
       Scanner sc=new
Scanner(System.in);
       System.out.println("Constraints: \n
1≤N≤104 \n 1≤Yi≤9");
       int N; // Declaring N for
number of seconds
   while(true){
  
       N=sc.nextInt();
       if(N<1 || N>104) //
Checking for correct input
       System.out.println("Value of N
exceeds limits. Please enter again");
       else
       break;
   }
       int Y[]=new int[N]; //
Declaring array of Yi for vertical positions
       for(int i=0;i<N;i++)
       {
         
       while(true)
       {
       Y[i]=sc.nextInt();
         
       if(Y[i]<1 || Y[i]>9)
// Checking for correct input
       System.out.println("Value of N
exceeds limits. Please enter again");
   else
      break;
       }
       }
       // Outer loop to print the
position for the given number of seconds
       for(int i=0;i<N;i++)
       {
       // Inner loop to print the
vertical position of the particle in the space
       for(int j=1;j<10;j++)
       {
       if(j==(10-Y[i])) // If
particle postion is same the prints '#'
       System.out.print("#");
       else // If empty postion
the print '.'
       System.out.print(".");
       }
       // For going into the next
line
       System.out.println();
       }
      
   }
}
----------------------------------------------------------------------------------------------------------------------
C++ VERSOIN:
#include <iostream>
using namespace std;
int main()
{
cout<<"Constraints: \n 1≤N≤104 \n 1≤Yi≤9\n";
int N; // Declaring N for number of seconds
   while(1){
  
       cin>>N;
       if(N<1 || N>104) //
Checking for correct input
   cout<<"Value of N exceeds limits. Please enter
again\n";
       else
       break;
   }
  
   int Y[N]; // Declaring Yi for vertical
positions
       for(int i=0;i<N;i++)
       {
         
       while(1)
       {
       cin>>Y[i];
         
       if(Y[i]<1 || Y[i]>9)
// Checking for correct input
          cout<<"Value of
N exceeds limits. Please enter again\n";
       else
       break;
       }
       }
      
       // Outer loop to print the
position for the given number of seconds
       for(int i=0;i<N;i++)
       {
       // Inner loop to print the
vertical position of the particle in the space
       for(int j=1;j<10;j++)
       {
       if(j==(10-Y[i])) // If
particle postion is same the prints '#'
       cout<<"#";
       else // If empty postion
the print '.'
       cout<<".";
       }
       // For going into the next
line
       cout<<"\n";
       }
return 0;
}
-----------------------------------------------------------------------------------------------------------------------
C CODE:
#include <stdio.h>
int main()
{
printf("Constraints: \n 1≤N≤104 \n 1≤Yi≤9\n");
int N; // Declaring N for number of seconds
while(1){
  
scanf("%d",&N);
if(N<1 || N>104) // Checking for correct
input
printf("Value of N exceeds limits. Please enter again\n");
else
break;
}
int Y[N]; // Declaring Yi for vertical
positions
for(int i=0;i<N;i++)
{
while(1)
{
scanf("%d",&Y[i]);
if(Y[i]<1 || Y[i]>9) // Checking for correct
input
printf("Value of N exceeds limits. Please enter again\n");
else
break;
}
}
  
// Outer loop to print the position for the given number of
seconds
for(int i=0;i<N;i++)
{
// Inner loop to print the vertical position of the
particle in the space
for(int j=1;j<10;j++)
{
if(j==(10-Y[i])) // If particle postion is same the prints
'#'
printf("#");
else // If empty postion the print '.'
printf(".");
}
// For going into the next line
printf("\n");
}
return 0;
}
OUTPUT:
