Created
January 10, 2022 16:27
-
-
Save hjroh0315/a868635b25c1a521e3de8657c7abb97f to your computer and use it in GitHub Desktop.
Pythonic한 입력법을 C++에 구현하는법
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <functional> | |
#include <vector> | |
#include <sstream> | |
#include <iterator> | |
#include <algorithm> | |
using namespace std; | |
template <class T, class Ty> | |
struct PipeOperation | |
{ | |
function<T(Ty)> func; | |
}; | |
template <class T, class Ty> | |
T operator| (Ty S, PipeOperation<T,Ty> P){return P.func(S);} | |
PipeOperation<vector<string>,string> split() | |
{ | |
PipeOperation<vector<string>,string> P; | |
P.func=[](string input){ vector<string> answer; stringstream ss(input); string temp; while (getline(ss, temp, ' ')) { answer.push_back(temp); } return answer; }; | |
return P; | |
} | |
string input() | |
{ | |
string i; | |
getline(cin,i); | |
return i; | |
} | |
template<class Fr, class To> | |
vector<To> fmap(To (*f)(Fr),vector<Fr> From) | |
{ | |
vector<To> vec; | |
transform(From.begin(),From.end(),back_inserter(vec),f); | |
return vec; | |
} | |
int _int(string s){return stoi(s);} | |
int main() | |
{ | |
for(int a:fmap(_int,input()|split()))cout << a << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment