Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Constraints + Formatting Validator
- #include<bits/stdc++.h>
- using namespace std;
- // -------------------- Input Checker Start --------------------
- // This function reads a long long, character by character, and returns it as a whole long long. It makes sure that it lies in the range [l, r], and the character after the long long is endd. l and r should be in [-1e18, 1e18].
- long long readInt(long long l, long long r, char endd)
- {
- long long x = 0;
- int cnt = 0, fi = -1;
- bool is_neg = false;
- while(true)
- {
- char g = getchar();
- if(g == '-')
- {
- if(!(fi == -1))
- cerr << "- in between integer\n";
- assert(fi == -1);
- is_neg = true; // It's a negative integer
- continue;
- }
- if('0' <= g && g <= '9')
- {
- x *= 10;
- x += g - '0';
- if(cnt == 0)
- fi = g - '0'; // fi is the first digit
- cnt++;
- // There shouldn't be leading zeroes. eg. "02" is not valid and assert will fail here.
- if(!(fi != 0 || cnt == 1))
- cerr << "Leading zeroes found\n";
- assert(fi != 0 || cnt == 1);
- // "-0" is invalid
- if(!(fi != 0 || is_neg == false))
- cerr << "-0 found\n";
- assert(fi != 0 || is_neg == false);
- // The maximum number of digits should be 19, and if it is 19 digits long, then the first digit should be a '1'.
- if(!(!(cnt > 19 || (cnt == 19 && fi > 1))))
- cerr << "Value greater than 1e18 found\n";
- assert(!(cnt > 19 || (cnt == 19 && fi > 1)));
- }
- else if(g == endd)
- {
- if(is_neg)
- x = -x;
- if(!(l <= x && x <= r))
- {
- // We've reached the end, but the long long isn't in the right range.
- cerr << "Constraint violated: Lower Bound = " << l << " Upper Bound = " << r << " Violating Value = " << x << '\n';
- assert(false);
- }
- return x;
- }
- else if((g == ' ') && (endd == '\n'))
- {
- cerr << "Extra space found. It should instead have been a new line.\n";
- assert(false);
- }
- else if((g == '\n') && (endd == ' '))
- {
- cerr << "A new line found where it should have been a space.\n";
- assert(false);
- }
- else
- {
- cerr << "Something weird has happened.\n";
- assert(false);
- }
- }
- }
- string readString(int l, int r, char endd)
- {
- string ret = "";
- int cnt = 0;
- while(true)
- {
- char g = getchar();
- assert(g != -1);
- if(g == endd)
- break;
- cnt++;
- ret += g;
- }
- if(!(l <= cnt && cnt <= r))
- cerr << "String length not within constraints\n";
- assert(l <= cnt && cnt <= r);
- return ret;
- }
- long long readIntSp(long long l, long long r) { return readInt(l, r, ' '); }
- long long readIntLn(long long l, long long r) { return readInt(l, r, '\n'); }
- string readStringLn(int l, int r) { return readString(l, r, '\n'); }
- string readStringSp(int l, int r) { return readString(l, r, ' '); }
- void readEOF()
- {
- char g = getchar();
- if(g != EOF)
- {
- if(g == ' ')
- cerr << "Extra space found where the file shold have ended\n";
- if(g == '\n')
- cerr << "Extra newline found where the file shold have ended\n";
- else
- cerr << "File didn't end where expected\n";
- }
- assert(g == EOF);
- }
- vector<int> readVectorInt(int n, long long l, long long r)
- {
- vector<int> a(n);
- for(int i = 0; i < n - 1; i++)
- a[i] = readIntSp(l, r);
- a[n - 1] = readIntLn(l, r);
- return a;
- }
- // -------------------- Input Checker End --------------------
- int main(){
- ios::sync_with_stdio(false);cin.tie(0);
- // CODE TO BE MODIFIED
- int t, x;
- t=readIntLn(1,100); // This reads an integer whose value is 1 <= t <= 100, and the line should end right after this integer.
- while(t--)
- {
- x=readIntLn(1,1000); // This reads an integer whose value is 1 <= x <= 1000, and the line should end right after this integer.
- }
- readEOF(); // This ensures that there is nothing more to read in the input file.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement