Plus Minus

Sort by

recency

|

297 Discussions

|

  • + 0 comments

    def plusMinus(arr): pos_num = 0 neg_num = 0 zeroes = 0 for i in arr:

        if i < 0:
            neg_num+=1
        elif i > 0:
    
            pos_num+=1
            # print(i)
        elif  i == 0:
            zeroes+=1
        else:
            return None
    value1 =pos_num/len(arr)
    value2 =neg_num/len(arr)
    value3 =zeroes/len(arr)
    print(f"{value1:.6f}")
    print(f"{value2:.6f}")
    print(f"{value3:.6f}")
    
  • + 0 comments
    def plusMinus(arr):
        # Write your code here
        plus=0
        minus=0
        zero=0
        
        for i in arr:
            if i>0:
                plus+=1
            elif i<0:
                minus+=1
            else:
                zero+=1
        print(round(plus/len(arr),6))
        print(round(minus/len(arr),6))
        print(round(zero/len(arr),6))
    
  • + 0 comments

    TypeScript Solution

    function plusMinus(arr: number[]): void {
    
        let zeros = 0
        let negatives = 0 
        let positives = 0 
        
        for (const i in arr ){
            if (arr[i] > 0 && arr[i] <=100) positives++;
            if (arr[i] === 0) zeros++;
            if (arr[i] < 0 && arr[i] >= -100) negatives++;
        }
        const z = zeros / arr.length
        const n = negatives / arr.length
        const p = positives / arr.length
        
        console.log(p.toFixed(6))
        console.log(n.toFixed(6))
        console.log(z.toFixed(6))
    }
    
  • + 0 comments

    float[] valores = {0,0,0}; // plus, minus, 0 foreach(int x in arr) { valores[x > 0 ? 0 : x < 0 ? 1 : 2]++;
    } Console.WriteLine(valores[0]/ arr.Count + "\n" + valores[1]/ arr.Count + "\n" + valores[2]/ arr.Count + "\n");

  • + 0 comments

    !/bin/python3

    import math import os import random import re import sys

    #

    Complete the 'plusMinus' function below.

    #

    The function accepts INTEGER_ARRAY arr as parameter.

    # def count_positive(a): return int(a > 0) def count_negative(a): return int(a < 0) def count_zero(a): return int(a == 0)

    def plusMinus(arr): # Write your code here l = len(arr) p = sum(map(count_positive, arr)) n = sum(map(count_negative, arr)) z = sum(map(count_zero, arr)) print(f"{p/l:.6f}") print(f"{n/l:.6f}") print(f"{z/l:.6f}") if name == 'main': n = int(input().strip())

    arr = list(map(int, input().rstrip().split()))
    
    plusMinus(arr)