We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Implementation
- Library Fine
- Discussions
Library Fine
Library Fine
+ 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; }
+ 0 comments C++ code solution
int libraryFine(int d1, int m1, int y1, int d2, int m2, int y2) { int result; if (y1 - y2 > 0){ result = 10000; } else if (y1 - y2 == 0){ if (m1 - m2 > 0){result = 500 * abs(m2-m1);} else if (m1 - m2 == 0){ if (d1 - d2 > 0){result = 15 * abs(d2-d1);} else {result = 0;} } else { result = 0; } } else { result = 0; } return result;
}
+ 0 comments int libraryFine(int d1, int m1, int y1, int d2, int m2, int y2) { if (y1 > y2) return 10000; else if (y1 < y2) return 0; else if (m1 > m2) return 500 * (m1 - m2); else if (m1 < m2) return 0; else if (d1 > d2) return 15 * (d1 - d2); else return 0; }
+ 0 comments JavaScript
function libraryFine(d1, m1, y1, d2, m2, y2) { // Write your code here if (y1 > y2) { return 10000 } else if (m1 > m2 && y1 >= y2) { return 500 * (m1 - m2) } else if (d1 > d2 && m1 >= m2 && y1 >= y2) { return 15 * (d1 - d2) } else { return 0 } }
+ 0 comments Java 8 :
public static int libraryFine(int d1, int m1, int y1, int d2, int m2, int y2) { if(y1<y2){ return 0; }else if(y1>y2){ return 10000; }else if(m1<m2){ return 0; }else if(m1>m2){ return (m1-m2)*500; } else if(d1>d2){ return (d1-d2)*15; } return 0; }
Load more conversations
Sort 926 Discussions, By:
Please Login in order to post a comment