{ }codelper
comparisonsP0227

Three-day temperature trend

Look at the daily high temperatures over three days and write down how they moved. The first line gives the number of records n, and each of the next n lines gives the temperatures a, b, c of the first, second and third day, separated by single spaces. For each record print one line: "up" if a < b < c, "down" if a > b > c, and "mixed" otherwise. If two or more days have the same temperature it neither kept rising nor kept falling, so it is "mixed" (e.g.
3 3 5). Rising then falling, or falling then rising, is also "mixed".

Input
1 ≤ n ≤ 1,000, −50 ≤ a, b, c ≤ 50 (integers)
Output
n lines, each one of up, down, mixed
Example 1 · stdin
4
3 8 12
12 8 3
5 9 2
4 4 6
stdout
up
down
mixed
mixed
main.py
Input (stdin)

When you run, these lines are fed to input()/stdin in order (the program doesn't stop to ask).

$ Ready

Open this on a computer to write and run code. On mobile you can read the problem and the solutions.

In other languagesShow solutions by language · 8 languages

Whether you can write a < b < c as in math differs by language.
Only Python reads it as a < b and b < c.
In JS it is computed without an error as (a < b) < c, and C and C++ under gcc compile it and compute it the same way (you only get a warning with -Wall; recent clang rejects it as an error by default).
The first comparison's true/false becomes 1/0 and is compared with c, so a record that rose then fell, like 5 9 2, becomes up whenever c is greater than 1.
Java and C# give a compile error because a boolean cannot be compared with an int, and Craykon tells you before running to split it as 'a < b && b < c', and TS rejects it with a type error because a boolean cannot be compared with a number.
So everywhere except Python, split it into two: a < b && b < c.
The second trap is the boundary.
Using <= instead of < makes 3 3 5 up.
The third trap is not converting the strings you read into numbers.
Values from Python input().split() or JS split(" ") are strings, so they compare character by character and "9" < "10" is false.
Convert with Python int, JS/TS Number or Craykon ToNumber before comparing.

Pythonmain.py · 10 lines
n = int(input())for _ in range(n):    a, b, c = map(int, input().split())    # Python은 a < b < c를 a < b and b < c로 읽는다    if a < b < c:        print("up")    elif a > b > c:        print("down")    else:        print("mixed")
JavaScriptmain.js · 11 lines
const lines = require("fs").readFileSync(0, "utf8").split("\n");const n = Number(lines[0]);const out = [];for (let i = 1; i <= n; i++) {  const [a, b, c] = lines[i].trim().split(/\s+/).map(Number);  // a < b < c는 (a < b) < c가 되어 true/false를 c와 비교한다. 둘로 나눠 쓴다  if (a < b && b < c) out.push("up");  else if (a > b && b > c) out.push("down");  else out.push("mixed");}console.log(out.join("\n"));
TypeScriptmain.ts · 12 lines
import { readFileSync } from "node:fs";const lines: string[] = readFileSync(0, "utf8").split("\n");const n: number = Number(lines[0]);const out: string[] = [];for (let i = 1; i <= n; i++) {  const [a, b, c]: number[] = lines[i].trim().split(/\s+/).map(Number);  // TS는 a < b < c를 타입 오류로 막는다(boolean과 number를 비교). 둘로 나눠 쓴다  if (a < b && b < c) out.push("up");  else if (a > b && b > c) out.push("down");  else out.push("mixed");}console.log(out.join("\n"));
JavaMain.java · 22 lines
import java.io.BufferedReader;import java.io.InputStreamReader;import java.util.StringTokenizer; public class Main {    public static void main(String[] args) throws Exception {        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));        int n = Integer.parseInt(br.readLine().trim());        StringBuilder out = new StringBuilder();        for (int i = 0; i < n; i++) {            StringTokenizer st = new StringTokenizer(br.readLine());            int a = Integer.parseInt(st.nextToken());            int b = Integer.parseInt(st.nextToken());            int c = Integer.parseInt(st.nextToken());            // a < b < c는 컴파일 오류다(boolean과 int는 비교할 수 없다)            if (a < b && b < c) out.append("up\n");            else if (a > b && b > c) out.append("down\n");            else out.append("mixed\n");        }        System.out.print(out);    }}
C#Main.cs · 21 lines
using System;using System.Text; class Program{    static void Main()    {        int n = int.Parse(Console.ReadLine().Trim());        var sb = new StringBuilder();        for (int i = 0; i < n; i++)        {            string[] p = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);            int a = int.Parse(p[0]), b = int.Parse(p[1]), c = int.Parse(p[2]);            // a < b < c는 컴파일 오류다. 둘로 나눠 &&로 잇는다            if (a < b && b < c) sb.Append("up\n");            else if (a > b && b > c) sb.Append("down\n");            else sb.Append("mixed\n");        }        Console.Write(sb);    }}
C++main.cpp · 15 lines
#include <iostream> int main() {    std::ios::sync_with_stdio(false);    int n;    std::cin >> n;    for (int i = 0; i < n; i++) {        int a, b, c;        std::cin >> a >> b >> c;        // a < b < c도 컴파일되지만 (a < b)의 true/false를 c와 비교한다        if (a < b && b < c) std::cout << "up\n";        else if (a > b && b > c) std::cout << "down\n";        else std::cout << "mixed\n";    }}
Cmain.c · 15 lines
#include <stdio.h> int main(void) {    int n;    scanf("%d", &n);    for (int i = 0; i < n; i++) {        int a, b, c;        scanf("%d %d %d", &a, &b, &c);        /* a < b < c도 컴파일되지만 (a < b)의 1이나 0을 c와 비교한다 */        if (a < b && b < c) puts("up");        else if (a > b && b > c) puts("down");        else puts("mixed");    }    return 0;}
Craykonmain.cray · 21 lines
n = Console.ReadLine().ToNumber();for (i = 0; i < n; i++){    p = Console.ReadLine().Trim().Split(" ");    a = p[0].ToNumber();    b = p[1].ToNumber();    c = p[2].ToNumber();    // a < b < c는 (a < b)의 참거짓을 c와 비교한다. 둘로 나눠 &&로 잇는다    if (a < b && b < c)    {        Console.WriteLine("up");    }    else if (a > b && b > c)    {        Console.WriteLine("down");    }    else    {        Console.WriteLine("mixed");    }}