Esempio n. 1
0
 private static void setStream(String in, String out) {
   try {
     System.setIn(new BufferedInputStream(new FileInputStream(in)));
     System.setOut(new PrintStream(out));
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 2
0
 // BEGIN CUT HERE
 public static void main(String[] args) {
   try {
     eq(0, (new AccessLevel()).canAccess(new int[] {0, 1, 2, 3, 4, 5}, 2), "DDAAAA");
     eq(1, (new AccessLevel()).canAccess(new int[] {5, 3, 2, 10, 0}, 20), "DDDDD");
     eq(2, (new AccessLevel()).canAccess(new int[] {}, 20), "");
     eq(3, (new AccessLevel()).canAccess(new int[] {34, 78, 9, 52, 11, 1}, 49), "DADADD");
   } catch (Exception exx) {
     System.err.println(exx);
     exx.printStackTrace(System.err);
   }
 }
Esempio n. 3
0
 // BEGIN CUT HERE
 public static void main(String[] args) {
   try {
     eq(0, (new KnockoutTourney()).meetRival(16, 1, 2), 1);
     eq(1, (new KnockoutTourney()).meetRival(16, 8, 9), 4);
     eq(2, (new KnockoutTourney()).meetRival(1000, 20, 31), 4);
     eq(3, (new KnockoutTourney()).meetRival(65536, 1000, 35000), 16);
     eq(4, (new KnockoutTourney()).meetRival(60000, 101, 891), 10);
   } catch (Exception exx) {
     System.err.println(exx);
     exx.printStackTrace(System.err);
   }
 }
 public static void main(String[] args) {
   try {
     eq(
         0,
         (new BallsSeparating_2())
             .minOperations(new int[] {1, 1, 1}, new int[] {1, 1, 1}, new int[] {1, 1, 1}),
         6);
     eq(
         1,
         (new BallsSeparating_2()).minOperations(new int[] {5}, new int[] {6}, new int[] {8}),
         -1);
     eq(
         2,
         (new BallsSeparating_2())
             .minOperations(
                 new int[] {4, 6, 5, 7}, new int[] {7, 4, 6, 3}, new int[] {6, 5, 3, 8}),
         37);
     eq(
         3,
         (new BallsSeparating_2())
             .minOperations(
                 new int[] {7, 12, 9, 9, 7},
                 new int[] {7, 10, 8, 8, 9},
                 new int[] {8, 9, 5, 6, 13}),
         77);
     eq(
         4,
         (new BallsSeparating_2())
             .minOperations(
                 new int[] {
                   842398, 491273, 958925, 849859, 771363, 67803, 184892, 391907, 256150, 75799
                 },
                 new int[] {
                   268944, 342402, 894352, 228640, 903885, 908656, 414271, 292588, 852057, 889141
                 },
                 new int[] {
                   662939, 340220, 600081, 390298, 376707, 372199, 435097, 40266, 145590, 505103
                 }),
         7230607);
     int[] a = new int[50];
     int[] b = new int[50];
     int[] c = new int[50];
     fill(a, 1);
     fill(b, 1);
     fill(c, 1);
     eq(5, (new BallsSeparating_2()).minOperations(a, b, c), 7230607);
   } catch (Exception exx) {
     System.err.println(exx);
     exx.printStackTrace(System.err);
   }
 }
  // BEGIN CUT HERE
  public static void main(String[] args) {
    try {
      eq(0, (new ImprovingStatistics_NOTSOLVED()).howManyGames(10, 8), 1);
      eq(1, (new ImprovingStatistics_NOTSOLVED()).howManyGames(100, 80), 6);
      eq(2, (new ImprovingStatistics_NOTSOLVED()).howManyGames(47, 47), -1);
      eq(3, (new ImprovingStatistics_NOTSOLVED()).howManyGames(99000, 0), 1000);
      eq(4, (new ImprovingStatistics_NOTSOLVED()).howManyGames(1000000000, 470000000), 19230770);
      eq(4, (new ImprovingStatistics_NOTSOLVED()).howManyGames(1750, 1015), 43);
      eq(4, (new ImprovingStatistics_NOTSOLVED()).howManyGames(32532, 3342), 266);

    } catch (Exception exx) {
      System.err.println(exx);
      exx.printStackTrace(System.err);
    }
  }
Esempio n. 6
0
    public void diff(int id, String small, String large) {
      try {
        Scanner sm = new Scanner(new File(small));
        Scanner lg = new Scanner(new File(large));
        int line = 0;
        while (sm.hasNextLine() && lg.hasNextLine()) {
          String s = sm.nextLine();
          String l = lg.nextLine();
          if (!s.equals(l)) {
            System.out.println(line + ">" + s);
            System.out.println(line + "<" + l);
          }
          line++;
        }

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
 public ArrayList<Reminder> getActiveReminders() {
   ArrayList<Reminder> reminders = new ArrayList<Reminder>();
   try {
     SQLiteDatabase dataBase = dbHelper.getReadableDatabase();
     Cursor cursor =
         dataBase.query(Reminder.ReminderEntry.TABLE_NAME, null, null, null, null, null, null);
     if (cursor.moveToFirst()) {
       while (cursor.isAfterLast() == false) {
         Reminder reminder = new Reminder();
         String date = cursor.getString(Reminder.ReminderEntry.INDEX_DATE);
         GregorianCalendar gregorianCalendar = DateUtils.parserStringDate(date);
         reminder.setDate(gregorianCalendar);
         GregorianCalendar currentDate = new GregorianCalendar();
         String state = cursor.getString(Reminder.ReminderEntry.INDEX_ESTADO);
         /*if(state.compareTo("RESOLVED") == 0 ||state.compareTo("resolved") == 0){
             continue;
         }*/
         if (gregorianCalendar.compareTo(currentDate) == 1) {
           reminder.setIdReminder(cursor.getInt(Reminder.ReminderEntry.INDEX_ENTRY_ID));
           reminder.setTitle(cursor.getString(Reminder.ReminderEntry.INDEX_TITLE));
           reminder.setNotes(cursor.getString(Reminder.ReminderEntry.INDEX_NOTES));
           reminder.setDaysAfter(cursor.getInt(Reminder.ReminderEntry.INDEX_DAYS_AFTER));
           reminder.setHourRange(cursor.getInt(Reminder.ReminderEntry.INDEX_HOUR_RANGE));
           String photoPath = cursor.getString(Reminder.ReminderEntry.INDEX_PHOTO_PATH);
           String voiceNotePath = cursor.getString(Reminder.ReminderEntry.INDEX_VOICE_NOTE_PATH);
           reminder.setPhotoPath(photoPath);
           reminder.setVoiceNotePath(voiceNotePath);
           reminder.defineDatesOfNotifications();
           reminders.add(reminder);
         }
         cursor.moveToNext();
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   Collections.sort(reminders);
   // Collections.reverse(reminders);
   return reminders;
 }