Planetary surveys
Task Description
It is the far future, and humanity is exploring the stars. We have collected data from space probes surveying the atmospheric composition of distant planets and we are looking for worlds with an atmosphere that could enable colonization. The atmosphere of a planet can be considered livable if the oxygen levels are between 19 and 24 percent and the nitrogen levels are between 76 and 81 percent and no dangerous elements are present in a concentration that is greater than 0.5 percent. Write a program that calculates how many of the planets surveyed have a livable atmosphere!
Input
The first line of the standard input contains the count of planets surveyed (1≤n≤100) and the count of dangerous elements observed on each of the planets (1≤m≤10). The next n lines contain observed levels of oxygen (1≤ox≤99) as a natural number, the observed levels of nitrogen (1≤nt≤99) as a natural number and the levels of m count of dangerous elements observed (0≤d≤2) as real numbers. The levels of all the elements in the atmosphere must add up to 100.
Output
The first line of the standard output should contain the count of observed planets that have a livable atmosphere.
Example
Input
5 3
5 94 0.5 0 0.
22 76 0.5 1 0.
21 79 0 0 0
61 35 2 1.5 0.
23 76 0.5 0 0.
Output
2
Code
File: Program.cs
Code:
// Specification: https://progalap.elte.hu/specifikacio/v1/?uuid=aae805d9-cafe-40f1-99ea-6959625c117a
// Algorithm: https://progalap.elte.hu/stuki/v1/?uuid=37d551a7-ffb8-4931-a44e-5631257a32ec
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CP2_task7
{
internal class Program
{
static void Main(string[] args)
{
int n, m, ox, nt, livableCnt = 0;
double d = 0.00;
bool acceptableOxygen, acceptableNitrogen, isDangerous = false;
string[] parts, firstLine = {""};
firstLine = Console.ReadLine().Split();
int.TryParse(firstLine[0], out n);
int.TryParse(firstLine[1], out m);
for (int i = 0; i < n; i++)
{
isDangerous = false;
parts = Console.ReadLine().Split();
int.TryParse(parts[0], out ox);
int.TryParse(parts[1], out nt);
acceptableOxygen = (ox >= 19 && ox <= 24);
acceptableNitrogen = (nt >= 76 && nt <= 81);
for (int j = 0; j < m; j++)
{
double.TryParse(parts[2 + j], out d);
if (d > 0.5) { isDangerous = true; }
}
if (acceptableOxygen && acceptableNitrogen && !isDangerous){ livableCnt++; }
}
Console.WriteLine(livableCnt);
}
}
}Algorithm: https://progalap.elte.hu/stuki/v1/?uuid=37d551a7-ffb8-4931-a44e-5631257a32ec

Specifickacio
Specification: https://progalap.elte.hu/specifikacio/v1/?uuid=aae805d9-cafe-40f1-99ea-6959625c117a
Specification
In: n ∈ N, m ∈ N, ox ∈ N[1..n], nt ∈ N[1..n], d ∈ R[1..n, 1..m]
Out: livableCount ∈ N
Pre: (1 <= n <= 100) and (1 <= m <= 10) and (∀i ∈ [1..n]: (1 <= ox[i] <= 99)) and (∀i ∈ [1..n]: (1 <= nt[i] <= 99)) and (∀i ∈ [1..n]: (∀j ∈ [1..m]: (0.0 <= d[i,j] <= 2.0))) and (∀i ∈ [1..n]: (ox[i] + nt[i] + (SUM(j=1..m, d[i,j])) = 100))
Post: livableCount = COUNT( i=1..n, (19 <= ox[i]) and (ox[i] <= 24) and (76 <= nt[i]) and (nt[i] <= 81) and (FORALL(j=1..m, d[i,j] <= 0.5)))Test Data
n: 5
m: 3
ox: [5, 22, 21, 61, 23]
nt: [94, 76, 79, 35, 76]
livableCount: 2
d:
- [0.5, 0.0, 0.5]
- [0.5, 1.0, 0.5]
- [0.0, 0.0, 0.0]
- [2.0, 1.5, 0.5]
- [0.5, 0.0, 0.5]