CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:luxask
Submission time:2017-10-06 20:45:45 +0300
Language:C++
Status:READY
Result:37
Feedback
groupverdictscore
#1ACCEPTED12
#2ACCEPTED25
#30
Test results
testverdicttimegroup
#1ACCEPTED0.05 s1details
#2ACCEPTED0.06 s2details
#3--3details

Compiler report

input/code.cpp: In function 'void test(int)':
input/code.cpp:61:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (unsigned i=1; i<n; i++)
                       ^
input/code.cpp:63:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (unsigned i=1; i<n; i++)
                          ^

Code

#include <iostream>
#include <vector>
#include <math.h>
#include <string>
using namespace std;
vector<int> getIndexes() {
int count, num;
vector<int> indexes;
cin >> count;
for (int i = 0; i < count; ++i)
{
cin >> num;
indexes.push_back(num);
}
return indexes;
}
int f(int x) {
return 9 * x * pow(10, x-1);
}
int getFirstNumber(int index, int numCount) {
return floor(index / (numCount * pow(10, numCount-1))) + 1;
}
int getMiddleNumber(int index, int numCount, int subNumber) {
return int(floor(floor(index / numCount) / pow(10, numCount - subNumber))) % 10;
}
int getLastNumber(int index, int numCount) {
return ((index / numCount) - 1) % 10;
}
int getNumberFromIndex(int index) {
if (index <= 9)
return index;
int numCount = 1;
while (index > f(numCount)) {
index -= f(numCount);
numCount++;
}
switch (int subNumber = index % numCount){
case 0:
return getLastNumber(index, numCount);
break;
case 1:
return getFirstNumber(index, numCount);
break;
default:
return getMiddleNumber(index, numCount, subNumber);
break;
}
}
void test(int n) {
string right, guess;
for (unsigned i=1; i<n; i++)
guess += to_string(getNumberFromIndex(i));
for (unsigned i=1; i<n; i++)
right += to_string(i);
right = right.substr(0, n-1);
if (right.compare(guess) == 0)
cout << "Right!";
else
cout << right << '\n' << guess << '\n';
}
void real() {
auto indexes = getIndexes();
for (unsigned i=0; i<indexes.size(); i++)
cout << getNumberFromIndex(indexes.at(i)) << '\n';
}
int main() {
//test(10000000);
real();
return 0;
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
1000
582
214
723
273
...

correct output
0
1
7
7
6
...

user output
0
1
7
7
6
...
Truncated

Test 2

Group: 2

Verdict: ACCEPTED

input
1000
615664
916441
627600
279508
...

correct output
1
2
3
2
2
...

user output
1
2
3
2
2
...
Truncated

Test 3

Group: 3

Verdict:

input
1000
672274832941907421
260504693279721732
646999966092970935
100853063389774434
...

correct output
7
2
2
0
9
...

user output
(empty)