Code submitted to Google Kickstart Online Judge is a complete solution that includes reading from stdin and output the answers for each test cases to stdout. There will be two test set which contain several test cases.
Passing the first test set awards you some points and passing the second extensive test set (usually containing a large number of test cases) gives you bonous points.
Below is the C++ template for submiting algorithms to the puzzles in Google Kickstart online judge. You are expected to read in the first number as the total test cases, and then read separately each test cases from stdin. And your solution should output each answer for each test cases in the format of “Case 1: Answer” …
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include <bits/stdc++.h> #include <iostream> #include <vector> #include <set> #include <unordered_map> #include <functional> #include <stack> #include <queue> #include <string> #include <sstream> #include <algorithm> #include <map> #include <unordered_set> #include <math.h> typedef long double LD; typedef long long LL; typedef int64_t I64; // Many of the solutions require mod by 10e^9+7 #define MOD 1000000007 // The least significant bit #define LSB(i) ((i) & -(i)) using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; for (auto case_num = 1; case_num <= T; ++ case_num) { int N; cin >> N; // process each case auto ans = 0; // CODE HERE // CODE HERE // output each answer for test case std::cout >> std::fixed; // cout >> std::setprecision(8); cout << "Case #" << case_num << ": " << ans << endl; } return 0; } |
#include <bits/stdc++.h> #include <iostream> #include <vector> #include <set> #include <unordered_map> #include <functional> #include <stack> #include <queue> #include <string> #include <sstream> #include <algorithm> #include <map> #include <unordered_set> #include <math.h> typedef long double LD; typedef long long LL; typedef int64_t I64; // Many of the solutions require mod by 10e^9+7 #define MOD 1000000007 // The least significant bit #define LSB(i) ((i) & -(i)) using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; for (auto case_num = 1; case_num <= T; ++ case_num) { int N; cin >> N; // process each case auto ans = 0; // CODE HERE // CODE HERE // output each answer for test case std::cout >> std::fixed; // cout >> std::setprecision(8); cout << "Case #" << case_num << ": " << ans << endl; } return 0; }
If you are using std::cin to read numbers, and read strings. You should use cin.ignore() to skip the new line characters before you use getline function. For example:
1 2 3 4 | cin >> N; cin.ignore(); // skip new line characters string line; getline(cin, line); // read next line |
cin >> N; cin.ignore(); // skip new line characters string line; getline(cin, line); // read next line
One common mistake is do the following when you try to read a line from stdin to C++ string:
1 | cin >> line; |
cin >> line;
This may not work as a whitespace, a tab will be considered a string terminator.
Good luck to your Google Kickstart (here is a sample problem) !
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: How to Fix the Wired Connection Dropping Momentary Due to Failling to Get a New IP via DHCP?
Next Post: Compute the Largest Substring Between Two Equal Characters using Hash Table