Thread: Algorithms

  1. #1
    Registered User
    Join Date
    Mar 2004


    1) Is there anyway to get the number of lines in a text file without having to scan through the whole file?

    2) How do I compare if a date falls in between a starting date with a duration. eg. Starting date = 1st March Duration 5 days. check if a user entered date falls in between it.

  2. #2
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    1) there's a command in unix wc -l that returns #lines
    2) check if users enter the starting month
    check if the date occurs during the duration date

    IF month_input == month_start
        IF date_input >= date_start AND date_input =< date_end
            THEN date input falls within the duration date
    Last edited by alphaoide; 03-08-2004 at 01:17 PM.
    source: compsci textbooks,, world wide web, common sense

  3. #3
    Registered User
    Join Date
    Mar 2002
    1) not that I know of

    2) use month numbers, not month names, then set up the protocol yourself. Use pencil and paper. Here's a general outline of how I would do it.

    general protocol:
    obtain start date
    loop five times through starting at start date
    advance date 1 day at a time
    if given date equals any of the five given dates in loop then it falls inside the loop.

    advance date protocol:
    if month == 1 && date == 31 advance month by 1 and date = 1;
    else if month == 2 && not leap year days == 28 advance month by 1 and date = 1;
    else if month == 12 && date == 31 then advance year by 1 and date and month = 1;
    else advance date by one

    leap year protocol:
    you can look it up

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting algorithms, worst-case input
    By Leftos in forum C++ Programming
    Replies: 17
    Last Post: 06-15-2009, 01:33 PM
  2. page replacement algorithms?
    By Extrovert in forum C++ Programming
    Replies: 1
    Last Post: 08-19-2005, 12:53 AM
  3. relative strength of encryption algorithms (blowfish, des, rinjdael...)
    By duck-billed platypus in forum A Brief History of
    Replies: 3
    Last Post: 12-30-2001, 04:20 PM
  4. C Algorithms
    By Garfield in forum C Programming
    Replies: 2
    Last Post: 09-28-2001, 02:59 AM