Advertisement
Guest User

Update Feb. 11 8:26 P.M

a guest
Feb 11th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <fstream>
  5. #include <sstream> //includes string stream
  6.  
  7.  
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.    string elementIn;
  14.    vector<string> v;
  15.  
  16.    ifstream file ("input.txt");
  17.    ofstream OF;
  18.  
  19.    stringstream middleman; //Used to hold stream so that it can be evaluated multiple times by getline
  20.    stringstream middleman2; //can't clear middleman within loop
  21.  
  22.    OF.open("output.txt");
  23.  
  24.  
  25.  
  26.     cout << "Only input allowed is card number followed by suit." << endl;
  27.     cout << "For example : Nine of Spades is: 9S. This is the only form allowed." << endl;
  28.     cout << "Also, there must be an input of 13 cards, no more or less." << endl;
  29.     cout << " " << endl;
  30.  
  31.     OF << "Only input allowed is card number followed by suit." << endl;
  32.     OF << "For example : Nine of Spades is: 9S. This is the only form allowed." << endl;
  33.     OF << "Also, there must be an input of 13 cards, no more or less." << endl;
  34.     OF << " " << endl;
  35.  
  36.     OF.close();
  37.  
  38.     int s=0, c=0, h=0, d=0, points=0;
  39.  
  40.         cout<< s << " " << c << " "<< h << " "<< d << endl;
  41.  
  42.  
  43.     if(file.is_open())
  44.     {
  45.        //file.eof() returns true if at end of file
  46.       //getLine automatically stops when at end of file
  47.  
  48.     /* By default getline(x, y) will take the entire line that is in the file x and transfer
  49.      * it to y. By adding the third parameter it overrides the function and counts spaces as
  50.      * newlines. */
  51.  
  52.         while(!file.eof())
  53.         {
  54.             while(getline(file,elementIn))
  55.             {
  56.                    middleman<< elementIn;
  57.  
  58.                    while(getline(middleman, elementIn, ' '))
  59.                    {
  60.                        middleman2 << elementIn;
  61.                        while(getline(middleman2, elementIn, ','))
  62.                        {
  63.                            cout<< elementIn<<endl;
  64.                            v.push_back(elementIn);
  65.                        }
  66.                        middleman.clear();
  67.                        middleman2.clear();
  68.                    }
  69.             }
  70.         }//ends while saga
  71.  
  72.     }//belongs to initial if
  73.     else
  74.     {
  75.         cout << "File not found" << endl; //shoddy try catch
  76.     }
  77.  
  78.  
  79. //From here on, the input is done. It is time to error check and allocate points if had is good.
  80.  
  81.  
  82.  
  83.         for(int i=0; i<v.size(); i++)
  84.            {
  85.             int count =0;
  86.             if(v.at(i).at(0)=='1'&& v.at(i).at(1)=='0')
  87.                 count++;
  88.             if(v.at(i).at(count+1) == 'C')
  89.                    c++;
  90.             else if(v.at(i).at(count+1) == 'S')
  91.                    s++;
  92.             else if(v.at(i).at(count+1) == 'H')
  93.                    h++;
  94.             else if(v.at(i).at(count+1)== 'D')
  95.                    d++;
  96.             else
  97.             cout<< "Bad format" << endl;
  98.  
  99.             cout<< v.at(i) << endl;
  100.  
  101.            }
  102.  
  103.  
  104.  
  105.  
  106.         if(h==0)
  107.             points+=3;
  108.         else if(d==0)
  109.             points+=3;
  110.         else if(s==0)
  111.             points+=3;
  112.         else if(c==0)
  113.             points+=3;
  114.         else
  115.             ;
  116.  
  117.         if(h==0)
  118.              points+=2;
  119.         else if(d==0)
  120.              points+=2;
  121.         else if(s==0)
  122.              points+=2;
  123.         else if(c==0)
  124.              points+=2;
  125.              else
  126.                ;
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.         cout<< "S " << s << " C " << c << " H "<< h << " D "<< d << endl;
  135.         cout << "Points: " << points << endl;
  136.  
  137. return 0;
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement