Coder Profile - Show off your skills, get a coder profile.
 
 
 
code pin board USACO gift1 Download Source Code
Author Details Code Information
Coding_Guy ( Gleb Sorokosh )

Pinned 5 Codes
Posted 5 Coding Articles

Send A Message
View Coders Profile
Language C++
Expires Never
Length 957 Characters (54 Lines)
Password no password
  1. /*
  2. ID: emergen1
  3. LANG: C++
  4. PROG: gift1
  5. */
  6.  
  7. #include<fstream>
  8. #include<string>
  9. #include<map>
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.           ofstream fout("gift1.out");
  15.           ifstream fin("gift1.in");
  16.  
  17.           int groupNum;
  18.           fin>> groupNum;
  19.  
  20.           map <string, int> people;
  21.           string keys[groupNum];
  22.  
  23.           string person;
  24.  
  25.           for (int i (0) ; i <groupNum ; i++)//now i have all the people
  26.           {
  27.                      fin>>person;
  28.                      keys[i] = person;
  29.                     people[person] = 0;
  30.           }
  31.  
  32.           string name;
  33.           int num, faces;
  34.  
  35.           while ( 1 )
  36.           {
  37.                        fin>>name >>num >>faces;//reads in, who, what hisoriginal amount, and howmany people to split it with
  38.                     if(num == 0 && faces == 0)
  39.                                  break;
  40.  
  41.                     people[name] -= (num - (num % faces));
  42.  
  43.                     for (int i(0) ; i < faces ; i++)//gives gifts to other friends
  44.                     {
  45.                                fin>>name;
  46.                               people[name] += (num / faces);
  47.                     }
  48.           }
  49.  
  50.           for (int i(0) ; i < groupNum ; i++)
  51.                     fout<<keys[i] <<" " <<people[keys[i]] <<endl;
  52.  
  53.           return 0;
  54. }
code pin board Back To Code Pin Board Post New Code
Please login to post comments.
Page 1 of 1
 
 
Part of the MyPingle Network
Development Blog :: Make A Donation :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents
Version 1.44.00
Copyright © 2007 - 2008, Scott Thompson, All Rights Reserved