Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <fstream>
- #include <sstream> //includes string stream
- using namespace std;
- int main()
- {
- string elementIn;
- vector<string> v;
- ifstream file ("input.txt");
- ofstream OF;
- stringstream middleman; //Used to hold stream so that it can be evaluated multiple times by getline
- stringstream middleman2; //can't clear middleman within loop
- OF.open("output.txt");
- cout << "Only input allowed is card number followed by suit." << endl;
- cout << "For example : Nine of Spades is: 9S. This is the only form allowed." << endl;
- cout << "Also, there must be an input of 13 cards, no more or less." << endl;
- cout << " " << endl;
- OF << "Only input allowed is card number followed by suit." << endl;
- OF << "For example : Nine of Spades is: 9S. This is the only form allowed." << endl;
- OF << "Also, there must be an input of 13 cards, no more or less." << endl;
- OF << " " << endl;
- OF.close();
- int s=0, c=0, h=0, d=0, points=0;
- cout<< s << " " << c << " "<< h << " "<< d << endl;
- if(file.is_open())
- {
- //file.eof() returns true if at end of file
- //getLine automatically stops when at end of file
- /* By default getline(x, y) will take the entire line that is in the file x and transfer
- * it to y. By adding the third parameter it overrides the function and counts spaces as
- * newlines. */
- while(!file.eof())
- {
- while(getline(file,elementIn))
- {
- middleman<< elementIn;
- while(getline(middleman, elementIn, ' '))
- {
- middleman2 << elementIn;
- while(getline(middleman2, elementIn, ','))
- {
- cout<< elementIn<<endl;
- v.push_back(elementIn);
- }
- middleman.clear();
- middleman2.clear();
- }
- }
- }//ends while saga
- }//belongs to initial if
- else
- {
- cout << "File not found" << endl; //shoddy try catch
- }
- //From here on, the input is done. It is time to error check and allocate points if had is good.
- for(int i=0; i<v.size(); i++)
- {
- int count =0;
- if(v.at(i).at(0)=='1'&& v.at(i).at(1)=='0')
- count++;
- if(v.at(i).at(count+1) == 'C')
- c++;
- else if(v.at(i).at(count+1) == 'S')
- s++;
- else if(v.at(i).at(count+1) == 'H')
- h++;
- else if(v.at(i).at(count+1)== 'D')
- d++;
- else
- cout<< "Bad format" << endl;
- cout<< v.at(i) << endl;
- }
- if(h==0)
- points+=3;
- else if(d==0)
- points+=3;
- else if(s==0)
- points+=3;
- else if(c==0)
- points+=3;
- else
- ;
- if(h==0)
- points+=2;
- else if(d==0)
- points+=2;
- else if(s==0)
- points+=2;
- else if(c==0)
- points+=2;
- else
- ;
- cout<< "S " << s << " C " << c << " H "<< h << " D "<< d << endl;
- cout << "Points: " << points << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement