Farmer - Breaking Yield Records
A farmer wishes to track during each harvest if he has broken previous best or worst records. The yield (in certain units) is passed as input to the program and the program must print how many times he broke his best record
along with the number of times he broke his worst record.
along with the number of times he broke his worst record.
Input Format:
The first line will contain the value of N which represents the units harvested in a specific yield.
The second line will contain the units harvested in N yields separated by a space.
The first line will contain the value of N which represents the units harvested in a specific yield.
The second line will contain the units harvested in N yields separated by a space.
Output Format:
The first line will contain the number of times he broke his best record followed by the number of times he broke his worst record, each separated by a space.
The first line will contain the number of times he broke his best record followed by the number of times he broke his worst record, each separated by a space.
Constraints:
3 <= N <= 100
3 <= N <= 100
Example Input/Output 1:
Input:
10
3 4 21 36 10 28 30 5 24 42
Input:
10
3 4 21 36 10 28 30 5 24 42
Output:
4 0
4 0
Explanation:
The best yield breaking records are for 4, 21, 36, 42. Hence 4 is printed.
The worst yield breaking record is 0 as none of the yields was less than 3 (which happens to be the first yield).
The best yield breaking records are for 4, 21, 36, 42. Hence 4 is printed.
The worst yield breaking record is 0 as none of the yields was less than 3 (which happens to be the first yield).
Example Input/Output 1:
Input:
9
10 5 20 20 4 5 2 25 1
Output:
2 4
2 4
Explanation:
The best yield breaking records are for 20, 25. Hence 2 is printed.
The worst yield breaking records are for 5, 4, 2, 1. Hence 4 is printed.
The best yield breaking records are for 20, 25. Hence 2 is printed.
The worst yield breaking records are for 5, 4, 2, 1. Hence 4 is printed.
Code:
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
int n,i,ele,b,w,best=0,worst=0;
cin>>n;
cin>>ele;
b=ele;
w=ele;
for(i=1;i<n;i++)
{
cin>>ele;
if(ele>b)
{
b=ele;
best++;
}
if(ele<w)
{
w=ele;
worst++;
}
}
cout<<best<<" "<<worst;
}
//follow n subscribe to get solutions through mail..
//follow n subscribe to get solutions through mail..
Please do comment If u have any Queries!
//code in c
ReplyDeleteint main()
{
int n,temp1=0,temp2=0,c1=0,c2=0;
scanf("%d",&n);
int arr[n];
for(int i=0;itemp2)
{
temp2=arr[i];
c2++;
}
}
printf("%d %d",c2,c1);
}
// sorry above is incomplete
Delete//full code
int main()
{
int n,temp1=0,temp2=0,c1=0,c2=0;
scanf("%d",&n);
int arr[n];
for(int i=0;itemp2)
{
temp2=arr[i];
c2++;
}
}
printf("%d %d",c2,c1);
}
something going wrong here ,i am trying to post full code but it displaying this much only.
Deletedude...u r using array to store elements...but it's not needed
Delete//RMK - java code
ReplyDeleteimport java.util.*;
public class Hello {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] yields = new int[n];
for(int i =0;itempMax)
{
tempMax = yields[i];
bestCount++;
}
if(yields[i]<tempMin)
{
tempMin = yields[i];
worstCount++;
}
}
System.out.println(bestCount+" "+worstCount);
}
}
code not coming properly
Deletechk post properly...
Deletegood work bro
ReplyDelete