Sort by

recency

|

60 Discussions

|

  • + 0 comments

    include

    using namespace std;

    int month[13];

    void updateLeapYear(int year) { if(year % 400 == 0) { month[2] = 29; } else if(year % 100 == 0) { month[2] = 28; } else if(year % 4 == 0) { month[2] = 29; } else { month[2] = 28; } }

    void storeMonth() { month[1] = 31; month[2] = 28; month[3] = 31; month[4] = 30; month[5] = 31; month[6] = 30; month[7] = 31; month[8] = 31; month[9] = 30; month[10] = 31; month[11] = 30; month[12] = 31; }

    int findLuckyDates(int d1, int m1, int y1, int d2, int m2, int y2) { storeMonth(); int result = 0; while(true) { int x = d1; x = x * 100 + m1; x = x * 10000 + y1; if(x % 4 == 0 || x % 7 == 0) { result++; } if(d1 == d2 && m1 == m2 && y1 == y2) { break; } updateLeapYear(y1); d1++; if(d1 > month[m1]) { d1 = 1; m1++; if(m1 > 12) { m1 = 1; y1++; } } } return result; }

    int main() { string str; int d1, m1, y1, d2, m2, y2; getline(cin, str); for(int i = 0; i < str.size(); i++) { if(str[i] == '-') { str[i] = ' '; } } stringstream ss; ss << str; ss >> d1 >> m1 >> y1 >> d2 >> m2 >> y2; int result = findLuckyDates(d1, m1, y1, d2, m2, y2); cout << result << endl; } Test cases are still failing.

  • + 0 comments

    this is java solution , i have commented on which line we have to do the changes and what we have to change

    public class Main {

    public static int month[];
    
    public static void main (String[] args) throws java.lang.Exception {
        Scanner in  = new Scanner(System.in);
    
        month = new int[15];
    
        String s = in.nextLine();
    
        StringTokenizer str = new StringTokenizer(s, "- ");
    
        int d1 = Integer.parseInt(str.nextToken());
        int m1 = Integer.parseInt(str.nextToken());
        int y1 = Integer.parseInt(str.nextToken());
        int d2 = Integer.parseInt(str.nextToken());
        int m2 = Integer.parseInt(str.nextToken());
        int y2 = Integer.parseInt(str.nextToken());
    
        int result = findPrimeDates(d1, m1, y1, d2, m2, y2);
        System.out.println(result);
    

    }

    public static void updateLeapYear(int year) {
        if(year % 400 == 0) {
            month[2] = 29;                                                     //1
        } else if(year % 100 == 0) {
            month[2] = 28;                                                      //2
        } else if(year % 4 == 0) {
            month[2] = 29;
        } else {
            month[2] = 28;
        }
    }
    
    public static void storeMonth() {
        month[1] = 31;
        month[2] = 28;
        month[3] = 31;
        month[4] = 30;
        month[5] = 31;
        month[6] = 30;
        month[7] = 31;
        month[8] = 31;
        month[9] = 30;
        month[10] = 31;
        month[11] = 30;
        month[12] = 31;
    }
    

    public static int findPrimeDates(int d1, int m1, int y1, int d2, int m2, int y2) { storeMonth();

        int result = 0;
    
        while(true) {
            int x = d1;
            x = x * 100 + m1;
            x = x * 10000 + y1;                                                         //3
            if(x % 4 == 0 || x % 7 == 0) {                                          //4
                result = result + 1;
            }
            if(d1 == d2 && m1 == m2 && y1 == y2) {
                break;
            }
            updateLeapYear(y1);
            d1 = d1 + 1;
            if(d1 > month[m1]) {
                m1 = m1 + 1;
                d1 = 1;
                if(m1 > 12) {
                    y1 =  y1 + 1;
                    m1 = 1;                                                   //5
                }
    
    
            }
        }
        return result;
    }
    

    }

  • + 0 comments

    Hint: Mistakes are present in 5 places only. Count the changes you make while correcting the logic. The change count must be exactly 5 and not more. Don't correct the full code based on your logic because it will make the test case fail.

  • + 0 comments

    what a waste of time. I am not here to test my knowledge on leap year cycles

  • + 0 comments

    There is definitely more than 5 things I want to change about this code xD. But indeed only 5 errors.