Sort by

recency

|

3150 Discussions

|

  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/OqevjJbsN2Q

    void plusMinus(vector<int> arr) {
        double sp, sn, sz, pa = 1.0 / arr.size();
        sp = sn = sz = 0;
        for(int i = 0; i < arr.size(); i++){
            if(arr[i] > 0) sp+= pa;
            else if(arr[i]<0) sn+= pa;
            else sz+= pa;
        }
        cout << setprecision(6) << fixed;
        cout << sp <<endl;
        cout << sn <<endl;
        cout << sz <<endl;
    }
    
  • + 0 comments

    C# : public static void plusMinus(List arr) { decimal positive =0; decimal negative = 0; decimal zero =0 ; int total= arr.Count;

    for (int i = 0; i < total; i++ ){
       if (arr[i] > 0){
           positive++;}
       else if (arr[i] <0){
           negative++;}
       else {zero++;}}
    

    Console.WriteLine(positive /total); Console.WriteLine(negative /total); Console.WriteLine(zero / total);

       else {zero++;}}
    

    Console.WriteLine(positive /total); Console.WriteLine(negative /total); Console.WriteLine(zero / total);

  • + 0 comments

    l = len(s) c1 = 0 c2 = 0 c3 = 0

    for i in s: if i>0: c1 += 1 if i<0: c2 += 1 elif i == 0: c3 += 1 listc = [] listc.append(c1) listc.append(c2) listc.append(c3) for i in listc: result = i/l print(f'{result}00000')

  • + 0 comments

    def plusMinus(arr): # Write your code here p=n=z=0

    for i in range(len(arr)):
        if arr[i]<0:
            n=n+1
        elif arr[i]>0:
            p=p+1
        else:
            z=z+1
    P=float(p/len(arr))
    N=float(n/len(arr))
    Z=float(z/len(arr))
    print(round(P, 6))
    print(round(N, 6))
    print(round(Z, 6))
    

    if name == 'main': n = int(input().strip())

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

    plusMinus(arr)

  • + 0 comments

    GO

    func plusMinus(arr []int32) {
        var positive, negative, zero float64
        var n = float64(len(arr))
    
    for i,_:= range arr{
        //For positive
        if arr[i] > 0{
            positive ++
        }else if arr[i] < 0{
            negative++
        }else{
            zero++
        }
    }
    fmt.Printf("%.6f \n%.6f \n%.6f", positive/float64(n), negative/float64(n), zero/float64(n))
    

    }