-
-
Save sifue/7880b4c7c119a03ee592 to your computer and use it in GitHub Desktop.
文字を分割して読み込んだりCPP
This file contains hidden or 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 <string> | |
| #include <vector> | |
| #include <cstdlib> | |
| #include <typeinfo> | |
| #include <sstream> | |
| using namespace std; | |
| vector<string> split(const string &s, char delim) { | |
| vector<string> elems; | |
| stringstream ss(s); | |
| string item; | |
| while (getline(ss, item, delim)) { | |
| if (!item.empty()) { | |
| elems.push_back(item); | |
| } | |
| } | |
| return elems; | |
| } | |
| int main() | |
| { | |
| string str; | |
| int count = 0; | |
| getline(cin, str); | |
| count = (atoi(str.c_str())); | |
| int data[count][2]; | |
| char delim = ' '; | |
| vector<string> splited; | |
| int a = 0; | |
| int b = 0; | |
| int a_win = 0; | |
| int b_win = 0; | |
| for (int i = 0; i < count; ++i) { | |
| getline(cin, str); | |
| splited = split(str, delim); | |
| a = atoi(splited[0].c_str()); | |
| b = atoi(splited[1].c_str()); | |
| if(a > b) ++a_win; | |
| if(b > a) ++b_win; | |
| } | |
| cout << a_win << " " << b_win << endl; | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment