Task: | Alien Invasion II |
Sender: | phid |
Submission time: | 2020-09-19 13:45:33 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.01 s | details |
#3 | ACCEPTED | 0.01 s | details |
Compiler report
input/code.cpp: In function 'std::__cxx11::string longDivision(std::__cxx11::string, int)': input/code.cpp:15:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] while (number.size() > idx) { ~~~~~~~~~~~~~~^~~~~ input/code.cpp: In function 'int main()': input/code.cpp:29:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int i = 0; i < x.size(); i++) { ~~^~~~~~~~~~ input/code.cpp:28:12: warning: unused variable 'm' [-Wunused-variable] int s, m; ^ input/code.cpp:32:22: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized] int add = 3 - (s % 3); ~~~^~~~
Code
#include <iostream> #include <string> using namespace std; string longDivision(string number, int divisor) { string ans; int idx = 0; int temp = number[idx] - '0'; while (temp < divisor) temp = temp * 10 + (number[++idx] - '0'); while (number.size() > idx) { ans += (temp / divisor) + '0'; temp = (temp % divisor) * 10 + number[++idx] - '0'; } if (ans.length() == 0) return "0"; return ans; } int main() { string x; cin >> x; //int t = x; int s, m; for (int i = 0; i < x.size(); i++) { s += (x[i] - '0'); } int add = 3 - (s % 3); string str = to_string(add) + x; cout << str << endl; cout << 3 << " " << longDivision(str, 3); return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
2368469234876449 |
correct output |
---|
22368469234876449 3 7456156411625483 |
user output |
---|
22368469234876449 3 7456156411625483 |
Test 2
Verdict: ACCEPTED
input |
---|
292929292929292929292929292931 |
correct output |
---|
129292929292929292929292929293... |
user output |
---|
129292929292929292929292929293... |
Test 3
Verdict: ACCEPTED
input |
---|
292929292929292929292929292979 |
correct output |
---|
129292929292929292929292929297... |
user output |
---|
129292929292929292929292929297... |