#include #include #include #include #include #include /* 含有stringstream类 */ #include using namespace std; /** * Definition for singly-linked list. */ struct ListNode { int val; ListNode *next; ListNode() : val(0), next(nullptr) {} ListNode(int x) : val(x), next(nullptr) {} ListNode(int x, ListNode *next) : val(x), next(next) {} }; /** * Definition for a binary tree node. */ struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode() : val(0), left(nullptr), right(nullptr) {} TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} }; void trimLeftTrailingSpaces(string &input) { input.erase(input.begin(), find_if(input.begin(), input.end(), [](int ch) { return !isspace(ch); })); } void trimRightTrailingSpaces(string &input) { input.erase(find_if(input.rbegin(), input.rend(), [](int ch) { return !isspace(ch); }) .base(), input.end()); } vector stringToIntegerVector(string input) { vector output; trimLeftTrailingSpaces(input); trimRightTrailingSpaces(input); input = input.substr(1, input.length() - 2); stringstream ss; ss.str(input); string item; char delim = ','; while (getline(ss, item, delim)) { output.push_back(stoi(item)); } return output; } int stringToInteger(string input) { return stoi(input); } ListNode *stringToListNode(string input) { // Generate list from the input vector list = stringToIntegerVector(input); // Now convert that list into linked list ListNode *dummyRoot = new ListNode(0); ListNode *ptr = dummyRoot; for (int item : list) { ptr->next = new ListNode(item); ptr = ptr->next; } ptr = dummyRoot->next; delete dummyRoot; return ptr; } string integerVectorToString(vector list, int length = -1) { if (length == -1) { length = list.size(); } if (length == 0) { return "[]"; } string result; for (int index = 0; index < length; index++) { int number = list[index]; result += to_string(number) + ", "; } return "[" + result.substr(0, result.length() - 2) + "]"; } string listNodeToString(ListNode *node) { if (node == nullptr) { return "[]"; } string result; while (node) { result += to_string(node->val) + ", "; node = node->next; } return "[" + result.substr(0, result.length() - 2) + "]"; } string boolToString(bool input) { return input ? "True" : "False"; } bool stringToBool(string input) { transform(input.begin(), input.end(), input.begin(), ::tolower); return input == "true"; } string treeNodeToString(TreeNode *root) { if (root == nullptr) { return "[]"; } string output = ""; queue q; q.push(root); while (!q.empty()) { TreeNode *node = q.front(); q.pop(); if (node == nullptr) { output += "null, "; continue; } output += to_string(node->val) + ", "; q.push(node->left); q.push(node->right); } return "[" + output.substr(0, output.length() - 2) + "]"; } TreeNode *stringToTreeNode(string input) { trimLeftTrailingSpaces(input); trimRightTrailingSpaces(input); input = input.substr(1, input.length() - 2); if (!input.size()) { return nullptr; } string item; stringstream ss; ss.str(input); getline(ss, item, ','); TreeNode *root = new TreeNode(stoi(item)); queue nodeQueue; nodeQueue.push(root); while (true) { TreeNode *node = nodeQueue.front(); nodeQueue.pop(); if (!getline(ss, item, ',')) { break; } trimLeftTrailingSpaces(item); if (item != "null") { int leftNumber = stoi(item); node->left = new TreeNode(leftNumber); nodeQueue.push(node->left); } if (!getline(ss, item, ',')) { break; } trimLeftTrailingSpaces(item); if (item != "null") { int rightNumber = stoi(item); node->right = new TreeNode(rightNumber); nodeQueue.push(node->right); } } return root; } string stringToString(string input) { assert(input.length() >= 2); string result; for (int i = 1; i < input.length() - 1; i++) { char currentChar = input[i]; if (input[i] == '\\') { char nextChar = input[i + 1]; switch (nextChar) { case '\"': result.push_back('\"'); break; case '/': result.push_back('/'); break; case '\\': result.push_back('\\'); break; case 'b': result.push_back('\b'); break; case 'f': result.push_back('\f'); break; case 'r': result.push_back('\r'); break; case 'n': result.push_back('\n'); break; case 't': result.push_back('\t'); break; default: break; } i++; } else { result.push_back(currentChar); } } return result; } void prettyPrintTree(TreeNode *node, string prefix = "", bool isLeft = true) { if (node == nullptr) { cout << "Empty tree"; return; } if (node->right) { prettyPrintTree(node->right, prefix + (isLeft ? "│ " : " "), false); } cout << prefix + (isLeft ? "└── " : "┌── ") + to_string(node->val) + "\n"; if (node->left) { prettyPrintTree(node->left, prefix + (isLeft ? " " : "│ "), true); } } void prettyPrintLinkedList(ListNode *node) { while (node && node->next) { cout << node->val << "->"; node = node->next; } if (node) { cout << node->val << endl; } else { cout << "Empty LinkedList" << endl; } } class Solution { public: int longestConsecutive(vector &nums) { return 0; } }; // Test int main() { string line; while (getline(cin, line)) { vector nums = stringToIntegerVector(line); int ret = Solution().longestConsecutive(nums); string out = to_string(ret); cout << out << endl; } return 0; }