927. Number of toys

 

A store offers an assortment of toys of various types. For each type, the number of toys and the price of one toy are known. Determine the total number of toys with a price less than 50 hryvnias.

 

Input. The first line contains an integer n (0 ≤ n ≤ 1000)the number of toy types in the price list. Each of the following n lines contains two integers:

·        a (0 ≤ a ≤ 1000) – the number of toys of this type, and

·        b (0 < b ≤ 10000) – the price of one toy of this type, in hryvnias.

 

Output. Print the total number of toys with a price less than 50 hryvnias.

 

Sample input

Sample output

3

2 100.00

5 23.00

10 22.50

15

 

 

SOLUTION

loops

 

Algorithm analysis

For each toy type, read its quantity and price. If the price of one toy is less than 50, add the quantity of this type to the total.

 

Algorithm implementation

Read the number of toy types n.

 

scanf("%d",&n);

 

Accumulate the number of required toys in the variable res.

 

res = 0;

 

Read and process the information about each toy type.

 

for (i = 0; i < n; i++)

{

  scanf("%d %lf",&num,&price);

  if (price < 50.0) res += num;

}

 

Print the answer.

 

printf("%d\n",res);

 

Java implementation

 

import java.util.*;

 

public class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

    //con.useLocale(new Locale("US"));

    //con.useLocale(Locale.US);

    int res = 0;

    int n = con.nextInt();

    for (int i = 0; i < n; i++)

    {

      int num = con.nextInt();       

      double price = con.nextDouble();

      if (price < 50.0) res += num;

    }

    System.out.println(res);

    con.close();

  }

}

 

Python implementation

Read the number of toy types n.

 

n = int(input())

 

Accumulate the number of required toys in the variable res.

 

res = 0

 

Read and process the information about each toy type.

 

for _ in range(n):

  num, price = input().split()

  num = int(num)

  price = float(price)

  if price < 50.0: res += num

 

Print the answer.

 

print(res)