Sort by

recency

|

1027 Discussions

|

  • + 0 comments
    int libraryFine(int d1, int m1, int y1, int d2, int m2, int y2) {
        if(y1<y2)return 0;
        if(y1==y2&&m1<m2) return 0;
    return (y1>y2)?10000:(m1>m2)?(m1-m2)*500:(d1>d2)?(d1-d2)*15:0;
    }
    
  • + 0 comments

    Python

    def libraryFine(d1, m1, y1, d2, m2, y2):
        # Write your code here
        ydiff = y1-y2
        if ydiff>=1:
            return 10000*ydiff
        elif ydiff<=-1:
            return 0
            
        else:
             mdiff = m1-m2
             if mdiff>=1:
                return 500*mdiff
             elif mdiff<=-1:
                return 0
             else:
                ddiff= d1-d2
                if ddiff>=1:
                    return 15*ddiff
                elif ddiff<=-1:
                    return 0
                else:
                    return 0
    
  • + 0 comments
    def libraryFine(d1, m1, y1, d2, m2, y2):
        # Write your code here
        if y1 > y2:
            return 10000
        
        if y1 == y2:
            if m1 == m2:
                if d1 > d2:
                    return 15 * abs(d2-d1)
            elif m1 > m2:
                return 500 * abs(m2-m1)
                
        return 0
    
  • + 0 comments

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

    int libraryFine(int d1, int m1, int y1, int d2, int m2, int y2) {
        int res = 0;
        if(y1<y2 || (y1 == y2 && m1<m2) || (y1 == y2 && m2 == m1 && d1<=d2)) return 0;
        if(y2 == y1){
            if(m1 == m2) return 15 * (d1 - d2);
            else return (m1 - m2) * 500;
        }
        else return 10000;
        return 0;
    }
    
  • + 1 comment

    This is my code and it worked but 13/16 test case only passed. Do anyone know the needed changes in my code to pass all the given test case?

    flag=False
    a=[int(i) for i in input().split(" ")]
    d=[int(i) for i in input().split(" ")]
    for i in range(1,len(a)+1):
        i=-i
        if a[i]>d[i] and i==-1:
            print(10000)
            flag=True
            break
        elif a[i]>d[i] and i==-2:
            print(500*(a[i]-d[i]))
            flag=True
            break
        elif a[i]>d[i] and i==-3:
            print(15*(a[i]-d[i]))
            flag=True
            break
    if flag==False:
        print(0)