CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:mika
Submission time:2017-10-04 22:21:53 +0300
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.04 s1details
#20.05 s2details
#30.04 s3details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:16:7: warning: unused variable '_n' [-Wunused-variable]
   int _n = n;
       ^

Code

#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main() {
	int c;
	cin >> c;

	int k = 0;
	while (k < c) {
		int n;
		cin >> n;
		k++;
		int _n = n;

		if (n < 10) {
			cout << n << endl;
			continue;
		}

		int nrot = 1;
		int ysi = 9;

		while (n - ysi * nrot > 0) {
			n -= nrot * ysi;
			ysi = ysi * 10;
			nrot++;
		}

		int mod = n % nrot;
		if (mod == 0)
			mod = nrot;

		int luku = pow(10, nrot - 1);

		if (mod == nrot)
			luku += n / nrot - 1;
		else
			luku += n / nrot;

		//cout << "n: " << _n << " luku: " << luku << " mod: " << mod << endl;

		string lukustr = to_string(luku);

		if (lukustr[mod])
			cout << lukustr[mod] << endl;
		else
			cout << luku % 10 << endl; 
	}

	return 0;
}

/*

1
10
100
1000
10000

1-9			1nro  9lukua   9*1		=9
10-99		2nro  90lukua  90*2		=180
100-999		3nro  900lukua 900*3	=2700
1000-9999	4nro  9000lukua 9000*4	=36000



n=50    30     0
*/

Test details

Test 1

Group: 1

Verdict:

input
1000
582
214
723
273
...

correct output
0
1
7
7
6
...

user output
0
0
7
7
6
...

Test 2

Group: 2

Verdict:

input
1000
615664
916441
627600
279508
...

correct output
1
2
3
2
2
...

user output
2
5
1
3
7
...

Test 3

Group: 3

Verdict:

input
1000
672274832941907421
260504693279721732
646999966092970935
100853063389774434
...

correct output
7
2
2
0
9
...

user output
7
-4
7
5
9
...