Thread: Solution problem

  1. #1
    Registered User
    Join Date
    Jan 2013

    Solution problem

    I have problem with solution for my homework. I have to write program which calculates number of girls that we can get their phone number and how much we need to pay. Input looks like this:

    5 - our starting budget;
    5 - number of friends;
    Peter - starting index is 1, and final is 5(because we are index 0)
    2 - number of girls we are interested in
    1 - index of girl(Mary)
    2 - index of girl(Angie)
    5 - number of connections between friends
    0 3 0 - friend[0](we) knows friend[3] and needs to pay 0 for his number
    3 4 5 - friend[3] knows friend[4] and he wants to be payed 5 bucks for friend[4] telephone number
    3 5 7 - friend[3] knows friend[5] and he wants to be payed 7 bucks for friend[5] telephone number
    4 1 9 - friend[4] knows friend[1] and he wants to be payed 9 bucks
    for his number
    5 1 1 - friend[5] knows friend[1] and he wants to be payed 1 dollar for his number

    Output should be:
    Mary 2 - we can get only Mary's number(and we need to pay 8 bucks for it, because we want to take cheaper option)

    Real input for girl name should be F01234 and that kind of things, so we can find out who are girls.

    Is it better to solve this via class or just in main?

    I have this so far:

    #define MAXF 20000    //max num of friends
    #define MAXC 1000000    //max num of connections between them
    #define MAXL 20    //max num of girls we are interested
    #define MAXB 100000000    //max budget
    int main()
        int budget;
        cin >> budget;    cin.get();
        int friendsCnt;
        cin >> friendsCnt;    cin.get();
        string friends[MAXF];
        friends[0] = "Tvrtko";
        for(int i = 1; i < friendsCnt+1; i++)
            getline(cin, friends[i]);
        int loversCnt;
        cin >> loversCnt;    cin.get();
        string lovers[MAXL];
        for(int i = 0; i < loversCnt; i++)
            int tmp;
            cin >> tmp;    cin.get();
            lovers[i] = friends[tmp];
        int connectionsCnt;
        cin >> connectionsCnt;    cin.get();
        for(int i = 0; i < connectionsCnt; i++)
            int indexF, indexC, price;
            cin >> indexF >> indexC >> price;    cin.get();
        return 0;
    I don't know how to proceed with this code. Any kind of help is appreciated.

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Liverpool UK
    you could use a class of course or non class based code, or another thing is to represent the friend with a struct:

    struct buddy
        std::string name;
        int knows;
        int payRate;
    You can then have a container of buddies (i would avoid using the word 'friend' for your data names) which you can initialise all the attribute values in a function and go from there with the rest of the program
    Last edited by rogster001; 05-23-2013 at 12:32 PM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A better solution to my problem
    By renegade007 in forum C Programming
    Replies: 2
    Last Post: 05-16-2013, 05:18 PM
  2. solution to the problem
    By vapanchamukhi in forum C Programming
    Replies: 14
    Last Post: 09-08-2008, 10:41 PM
  3. Problem and Solution
    By DavidP in forum Tech Board
    Replies: 3
    Last Post: 08-18-2003, 02:23 AM
  4. BASIC problem... no solution?
    By CodeMonkey in forum C++ Programming
    Replies: 10
    Last Post: 01-21-2003, 07:14 PM
  5. Odd solution to an odd problem
    By Zeeshan in forum A Brief History of
    Replies: 8
    Last Post: 07-20-2002, 05:44 PM