Question

In: Computer Science

C Programming Language Problem Title : Museum Heist Jojo loves art. In his free time, he...

C Programming Language

Problem Title : Museum Heist

Jojo loves art. In his free time, he usually goes to the museum and admires the artwork there. since Jojo loves are so much, he is planning a heist at the museum. Jojo knows the price of every piece of art and doesn't want to raise suspicion, so he decided to steal the second most expensive art piece. It is guaranteed that there are at least two art pieces with different prices.

Format Input

A line with integer N followed by another line of N numbers denoting the value of Ai.

Format Output

A single line of integer denoting the price of the second most expensive art piece.

Constraints

¶ 2 ≤ N ≤ 10^5

¶ 1 ≤ Ai ≤ 10^9

Sample Input 1

5

1 7 2 5 3

Sample Output 1

5

Sample Input 2

4

1 7 9 9

Sample Output 2

7

Sample Input 3

7

11 11 13 13 13 12 11

Sample Output 3

11

Solutions

Expert Solution

/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>

int main()
{
    int i,n,a[100],l=0,f=0,s=0,temp;

   
   scanf("%i",&n);//inputing N
   for(i=0;i<n;i++)
   {
       scanf("%i",&a[i]);//inputting N number of items
   }
   for(i=0;i<n;i++)
   {
       
      f=0;
      if(a[i]>l)//check if each element is less than l
      {
          f++;//flag to check if a new large element is found
          temp=l;//to store the previous large
          l=a[i];//new large is assigned
      }
      if(f==1)//if new large is found 
      {
          s=temp;//second largest is the previous large element
      }
      if((a[i]>s)&&(a[i]!=l))/*condition useful if large element is first element in array*/
      {
          s=a[i];
      }
   }
   printf("%d",s);

    return 0;
}


Related Solutions

C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
C Programming Language Problem Title : Take Three Jojo just graduated and moved up to grade...
C Programming Language Problem Title : Take Three Jojo just graduated and moved up to grade 4. Today is his first day in 4th grade. Unfortunately, the lessons are held online because of the pandemic. So that the quality of learning remains good, Jojo's teacher gives a hard task for 4th grader. After the 4th graders finished their first task which is prime factorization. Jojo's teacher set up a game for the stundets. The game is very simple. Given N...
C Programming Language Problem Title : 4th Grade Jojo just graduated and moved up to grade...
C Programming Language Problem Title : 4th Grade Jojo just graduated and moved up to grade 4. Today is his first day in 4th grade. Unfortunately, the lessons are held online because of pandemic. So that the quality of learning remains good, Jojo’s teacher gives a hard task for 4th grader. The first task is to find the prime factorization of a number. Prime number is a natural number greater than 1 that is not a product of two smaller...
C PROGRAMMING LANGUAGE PROBLEM TITLE : ARRAY usually, if people want to input number into an...
C PROGRAMMING LANGUAGE PROBLEM TITLE : ARRAY usually, if people want to input number into an array, they will put it from index 0 until N - 1 using for. But, Bibi is bored to code like that. So, she didin't want to input the number that way. So Bibi challenged you to make a program that will read a sequence (represent index) that she made, then input the number to an array but input it with the same sequence...
C PROGRAMMING LANGUAGE Problem title : Bibi's Array Bibi also has an array containing N elements....
C PROGRAMMING LANGUAGE Problem title : Bibi's Array Bibi also has an array containing N elements. Like Lili, Bibi wants to know the highest frequency (most occurrences) and all elements which have that frequency. Format Input The first line contains an integer T stating the number of test cases. For each test case, the first line contains a single integer N which indicate the number of element in the array. The next line contains N integers Xi (1≤ i ≤...
C Programming Language Title : Making wave In Physics, Mathematics, and related fields, a wave is...
C Programming Language Title : Making wave 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...
David donated a painting to the Leigh Yawkey Woodson Art Museum. He bought the painting 20...
David donated a painting to the Leigh Yawkey Woodson Art Museum. He bought the painting 20 years ago while on a European vacation for $6,000. David had the painting appraised by the owner of Nature's Beauty art store in Eagle River, a qualified art appraiser, who estimated its value to be $11,000. David believed the painting was worth more than $11,000, so he had it appraised by an art dealer in New York. That dealer, also a qualified art appraiser,...
David donated a painting to the Leigh Yawkey Woodson Art Museum. He bought the painting 20...
David donated a painting to the Leigh Yawkey Woodson Art Museum. He bought the painting 20 years ago while on a European vacation for $6,000. David had the painting appraised by the owner of Nature's Beauty art store in Eagle River, a qualified art appraiser, who estimated its value to be $11,000. David believed the painting was worth more than $11,000, so he had it appraised by an art dealer in New York. That dealer, also a qualified art appraiser,...
Be sure to use only C for the Programming Language in this problem. Before we start...
Be sure to use only C for the Programming Language in this problem. Before we start this, it is imperative that you understand the words “define”, “declare” and “initialize” in context of programming. It's going to help you a lot when following the guidelines below. Let's begin! Define two different structures at the top of your program. be sure to define each structure with exactly three members (each member has to be a different datatype). You may set them up...
C programming problem < purpose: need to find time and space complexities in this problem and...
C programming problem < purpose: need to find time and space complexities in this problem and which function(algorithm) will be used in this problem> I have to design an efficient algorithm which solves this problem. Also, it needs to include time and space complexities of this algorithm. There is a matrix (N times N) of integers which rows and columns are sorted in non-decreasing order. A sorted matrix and integer M will be given and we need to find the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT