Number of toys#927

Number of toys (Editorial)

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

Algorithm implementation

Read the number of toy types .

scanf("%d",&n);

Accumulate the number of required toys in the variable .

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 = int(input())

Accumulate the number of required toys in the variable .

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)