Task: | Ruudukko |
Sender: | ArturT |
Submission time: | 2019-10-04 20:04:22 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | WRONG ANSWER | 0.01 s | details |
#3 | WRONG ANSWER | 0.01 s | details |
#4 | WRONG ANSWER | 0.01 s | details |
#5 | WRONG ANSWER | 0.01 s | details |
#6 | WRONG ANSWER | 0.01 s | details |
Compiler report
input/code.cpp: In function 'int calc(int, bool)': input/code.cpp:32:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int i = 0; i <= inputStr.size() - 1; i++) { ~~^~~~~~~~~~~~~~~~~~~~~~ input/code.cpp:39:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int b = 0; b < inputStr.size()-i+1; b++) { ~~^~~~~~~~~~~~~~~~~~~~~ input/code.cpp:33:8: warning: variable 'roundedUp' set but not used [-Wunused-but-set-variable] bool roundedUp = false; ^~~~~~~~~ input/code.cpp:28:6: warning: unused variable 'result' [-Wunused-variable] int result = 0; ^~~~~~ input/code.cpp:30:15: warning: unused variable 'zeroes' [-Wunused-variable] unsigned int zeroes = inputStr.size() - 1; ^~~~~~
Code
#include<iostream> #include<vector> #include <string> #include <math.h> using namespace std; int btd(int n) { int num = n; int dec_value = 0; int base = 1; int temp = num; while (temp) { int last_digit = temp % 10; temp = temp / 10; dec_value += last_digit * base; base = base * 2; } return dec_value; } int calc(int input, bool roundUp) { int result = 0; string inputStr = to_string(input); unsigned int zeroes = inputStr.size() - 1; int rounded = 0; for (int i = 0; i <= inputStr.size() - 1; i++) { bool roundedUp = false; int cur = 0; if (!roundUp) { char curChar = inputStr[i]; cur = (int)curChar - 48; if (cur > 1) { // eg. 200 -> 111 for (int b = 0; b < inputStr.size()-i+1; b++) { inputStr[inputStr.size()-b] = 1+48; cur = 1; } } rounded += cur * pow(10, inputStr.size() - 1 - i); } else { char curChar = inputStr[inputStr.size()-i-1]; cur = (int)curChar - 48; if (cur > 1) { int temp = input; temp /= pow(10, i+1); temp *= pow(10, i+1); temp = temp + pow(10, i+1); rounded = temp; roundedUp = true; } else { rounded += cur * pow(10, i); } } } return rounded; } int main() { int rows = 1; cin >> rows; vector< vector<int> > inputs; for (int i = 0; i < rows; i++) { int input1=0; int input2=0; cin >> input1 >> input2; vector<int> input = { input1, input2 }; inputs.push_back(input); } for (int i = 0; i < rows; i++) { int result = 0; int roundedA = calc(inputs[i][0], true); int roundedB = calc(inputs[i][1], false); int a = btd(roundedA); // a = a-1; //a--; int b = btd(roundedB); result = b - a + 1; if (roundedA == roundedB) { //result = b - a; // result++; } else { //result = b - a + 1; } if (a>b) { result = 0; } cout << result << endl; } }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
1 |
correct output |
---|
1 |
user output |
---|
1 |
Test 2
Verdict: WRONG ANSWER
input |
---|
2 |
correct output |
---|
1 2 2 1 |
user output |
---|
1 1 |
Test 3
Verdict: WRONG ANSWER
input |
---|
5 |
correct output |
---|
1 2 3 4 5 2 1 4 3 6 3 4 1 2 7 4 3 2 1 8 5 6 7 8 1 |
user output |
---|
1 1 1 1 1 |
Test 4
Verdict: WRONG ANSWER
input |
---|
42 |
correct output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
1 1 1 1 1 ... |
Test 5
Verdict: WRONG ANSWER
input |
---|
99 |
correct output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
1 1 1 1 1 ... Truncated |
Test 6
Verdict: WRONG ANSWER
input |
---|
100 |
correct output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
1 1 1 1 1 ... Truncated |