import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
n = int(input())# the number of temperatures to analyse
x = 0
tpos = []
tneg = []
mmm = False
nnn = False
for i in input().split():
# t: a temperature expressed as an integer ranging from -273 to 5526
t = int(i)
if x < t :
tpos = [t]
elif x > t :
tneg = [t]
if len(tpos) > 0 :
m = min(tpos)
mmm = True
elif len(tpos) == 0 :
mmm = False
if len(tneg) > 0 :
n = max(tneg)
nnn = True
elif len(tneg) == 0 :
nnn = False
if nnn == True and mmm == True :
mm = m*m
nn = n*n
if nn > mm :
result = m
elif mm > nn :
result = n
elif mm == nn :
result = m
if nnn == True and mmm == False :
result = max(tneg)
if nnn == False and mmm == True :
result = min(tmax)
if nnn == False and mmm == False :
result = 0
# Write an action using print
print("Debug messages...", file=sys.stderr)
print(result)
Please help i canât find problem in code (it is in python 3)
class Solution
{
public int cons(){inputs}
static void Main(string[] args)
{
string[] arr1= new string();
string[] arr2= new string();
int n = int.Parse(Console.ReadLine()); // the number of temperatures to analyse
string[] inputs = new string();
I donât know why my variable is not always responding to my if test.
Iâm trying to solve in java script and have written this code after the code provided initialy:
let posT=5526, negT= -273, T=null;
for (let i = 0; i < n; i++) {
if (inputs[i]>=0 && inputs[i] < posT) {posT=inputs[i]}
if (inputs[i]<0 && inputs[i] > negT) {negT=inputs[i]}
console.error(posT);
}
if (posT <= -negT) {T=posT}
else if (posT > -negT) {T=negT}
console.error(".");
console.log(T);
console.error(".");
for (let i = 0; i < n; i++) {console.error(inputs[i])}
console.error(".");
console.error(posT);
console.error(negT);
I was expecting my posT variable to be 5 at i=1 on the for loop, but itâs not working,but it does works for some other values. That also happens with negT on other tests
So thats my Code on C# i only got a score of 81% and i dont know why can anyone help me?
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
class Solution
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine()); // the number of temperatures to analyse
string[] inputs = Console.ReadLine().Split(' ');
int temp = 0; // Ausgegebene Temperatur
int maxP = 5526; // Höchsttemperatur Plus
int maxM = -273; // Höchsttemperatur minus
int Null = 0;
for (int i = 0; i < n; i++)
{
int t = int.Parse(inputs[i]);// a temperature expressed as an integer ranging from -273 to 5526
Console.Error.WriteLine(inputs[i]);
if ( (Null < t) & (t < maxP) & (maxM * -1 >= t))
{
maxP = t;
temp = maxP;
}
else if ( (Null > t) & (t > maxM) & (maxP * -1 <= t))
{
maxM = t;
temp = maxM;
}
}
// Write an action using Console.WriteLine()
// To debug: Console.Error.WriteLine("Debug messages...");
if ( temp != 0)
{
if (maxP * -1 == temp)
{
Console.WriteLine(maxM * -1);
}
else
{
Console.WriteLine(temp);
}
}
else
{
Console.WriteLine(0);
}
}
}