Coder Profile - Show off your skills, get a coder profile.
 
 
 
code pin board CCC S3 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 2,481 Characters (120 Lines)
Password no password
  1. #include<vector>
  2. #include<fstream>
  3. using namespace std;
  4.  
  5. vector <int> student1;
  6. vector <int> student2;
  7.  
  8.  
  9. ///////////////////////
  10.  
  11.  
  12. vector<int> circleOfFriends(vector <int> student1, vector <int> student2)
  13. {
  14.           vector <int> completeC;
  15.           completeC.push_back(student1[0])
  16.  
  17.           for (int i(1) ; i < student1.size() ; i++)
  18.           {
  19.  
  20.                     if (student1[i] == student2[i-1])
  21.                      completeC.push_back(student1[i]);
  22.  
  23.                     else
  24.                     {
  25.                                   completeC.push_back(0);//separates all the friends
  26.                                   completeC.push_back(student1[i])
  27.            }
  28.  
  29.           }
  30.  
  31.           return completeC;//returns vector of circles of friends
  32. }
  33.  
  34.  
  35. //-----------------------------General Calc------------------------------//
  36.  
  37.  
  38. int generalCalc(vector <int> student1, vector <int> student2, int f1, int f2)
  39. {
  40.  
  41.           vector <int> :: const_iterator ZeroHolder;//these will keep track of "0"'s
  42.  
  43.             //getting the circle of friends
  44.           vector <int> sortedVec = circleOfFriends(vector <int> student1, vector <int> student2);
  45.  
  46.             ZeroHolder = find(sortedVec.begin(), sortedVec.end(), 0);
  47.              if (ZeroHolder != sortedVec.end())//there is more than one circle of friends
  48.              {
  49.                      vector <int> :: const_iterator ZeroHolder2;
  50.                     vector <int> :: const_iterator Friend1;
  51.                     vector <int> :: const_iterator Friend2;
  52.  
  53.  
  54.           }
  55.  
  56.      else//there is only one circle of friends
  57.             {
  58.                     vector <int> :: const_iterator Friend1;
  59.                     vector <int> :: const_iterator Friend2;
  60.  
  61.                     Friend1 = find(sortedVec.begin(), sortedVec.end(), f1);
  62.                     Friend2 = find(sortedVec.begin(), sortedVec.end(), f2);
  63.                     if ((Friend1 != sortedVec.end()) && (Friend2 != sortedVec.end()))//freinds
  64.                     {
  65.                                int count; //will hold the separation
  66.                               for (int i(Friend1) ; i < Friend2 ; i++)
  67.                                         count++;
  68.                     }
  69.  
  70.                     else
  71.                               return -1;//not friends
  72.  
  73.                     return count;
  74.           }
  75. }
  76.  
  77.  
  78. //----------------------------main-------------------------//
  79.  
  80.  
  81. int main()
  82. {
  83.  
  84.           ofstream fout("s3.out");
  85.           ifstream fin("s3.in");
  86.  
  87.           int s1, s2;
  88.  
  89.           int fa;//friendship amount
  90.           fin>>fa;
  91.  
  92.           for (int i(0) ; i < fa ; i++)
  93.           {
  94.  
  95.                     fin>> s1 >> s2;
  96.  
  97.                     //doesn't belong here :
  98.  
  99.                     student1.push_back(s1);
  100.                     student2.push_back(s2);
  101.  
  102.           }
  103.  
  104.           //////////////////////
  105.  
  106.           int f1, f2;
  107.           while( 1 )
  108.           {
  109.  
  110.                      fin>>f1>>f2;
  111.                     if ((f1 == 0) || (f2 == 0)) break;
  112.  
  113.                     if (generalCalc(student1, student2, f1, f2) == -1) fout<<"NO";
  114.  
  115.                     else fout<<"YES"<<generalCalc(student1, student2, f1, f2);
  116.  
  117.              }
  118.  
  119.           return 0;
  120. }
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