CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:Nanohenry
Submission time:2017-10-10 22:06:54 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:45:28: error: too few arguments to function 'std::string toString(int, int)'
    result += toString(index);
                            ^
input/code.cpp:13:8: note: declared here
 string toString(int val, int a) {
        ^

Code

#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
//#include <sstream>
using namespace std;
unsigned getDigits(unsigned int value) {
return value > 0 ? (int) log10 ((double) value) + 1 : 1;
}
string toString(int val, int a) {
string res;
for (int i = 0; i < a; i++) {
res += (char)val % 10;
val /= 10;
}
reverse(res.begin(), res.end());
return res;
}
int main() {
int amount;
cin >> amount;
int *a = new int[amount];
int cur;
int index;
int size;
int digits;
string result;
for (int i = 0; i < amount; i++) {
cin >> a[i];
}
for (int i = 0; i < amount; i++) {
cur = a[i];
index = 1;
size = 0;
digits = 0;
//stringstream ss;
for (; size <= cur; index++) {
digits = getDigits(index);
//ss << index;
result += toString(index);
size += digits;
}
cout << result.at(cur - 1) << '\n';
}
//while (1);
return 0;
}