Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // 2017-01-03
- // 2017-01-03
- //
- // Created by Jamie on 2017. 5. 21..
- // Copyright © 2017년 Jamie. All rights reserved.
- //
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <unordered_set>
- using namespace std;
- using mySet = unordered_set<int>;
- mySet calcSet(mySet a, mySet b) {
- mySet result;
- if(a.size() == 0) return b;
- if(b.size() == 0) return a;
- for( auto i : a) {
- for( auto j : b) {
- result.emplace(i+j);
- }
- }
- return result;
- }
- mySet mergeSet(mySet a, mySet b) {
- mySet result;
- for(auto i : a) {
- result.emplace(i);
- }
- for( auto i : b) {
- result.emplace(i);
- }
- return result;
- }
- void showSet(mySet myset) {
- cout << " { " ;
- for(auto a: myset) {
- cout << a << " " ;
- }
- cout << " }" << endl;
- }
- mySet getCase(int k) {
- mySet mset;
- if ( k==1) {
- mset = {1};
- } else if (k==2 ) {
- mset = {2,5,10};
- } else if (k==3) {
- mset = {3,4,6,9,11};
- } else if (k==4) {
- mset = {4,5,7,10,12,15,20};
- }
- for (int i=1 ; (i<= k/2) && (k>4) ; i++) {
- mySet temp;
- temp = calcSet(getCase(i), getCase(k-i));
- mset = mergeSet(mset,temp);
- }
- return mset;
- }
- bool IsCheck(int n, int k) {
- mySet result;
- result = getCase(k);
- // showSet(result);
- return (result.find(n) != end(result));
- }
- // n sheep, k stick
- string IsCheckRomanStyle(int n, int k) {
- // cout << n << " " << k << " ";
- return (IsCheck(n,k))? "O" : "X";
- }
- void GetDataFromFile(string filename) {
- ifstream fin(filename);
- string filenameOut = filename.replace(filename.length()-3, 3, ".out");
- ofstream fout(filenameOut);
- if( !fin) {
- cerr << "Cannot open the file" << endl;
- return;
- }
- int totalCase = 0;
- fin >> totalCase; //cout << totalCase << endl
- while ( totalCase--) {
- int n=0;
- int k=0;
- fin >> n >> k;
- // cout << IsCheckRomanStyle(n,k) << endl;
- fout << IsCheckRomanStyle(n,k) << endl;
- }
- fout.close();
- fin.close();
- }
- int main(int argc, const char * argv[]) {
- // GetDataFromFile("Set1.in");
- // GetDataFromFile("Set2.in");
- // GetDataFromFile("Set3.in");
- // GetDataFromFile("sample_03.in");
- GetDataFromFile(argv[1]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement