CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:Katajisto
Submission time:2017-10-04 13:58:06 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:38:32: error: 'pow' was not declared in this scope
     sub = i * 9 * pow(10, i - 1);
                                ^
input/code.cpp:37:15: warning: unused variable 'tempnum' [-Wunused-variable]
     long long tempnum = num;
               ^
input/code.cpp:54:41: error: 'pow' was not declared in this scope
   nums = region * 9 * pow(10, region - 1);
                                         ^
input/code.cpp:60:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (b < queries.size())
                        ^
input/code.cpp:10:6: warning: unused variable 'wait' [-Wunused-variable]
  int wait;
      ^

Code

#include <vector>
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
long long int taken = 1;
int originalnum;
int main()
{
	int wait;
	int q;
	long int b = 0;
	cin >> q;
	vector<long long int> queries = {};
	for (long long int t = 1; t <= q; t++)
	{
		long long int tempq;
		cin >> tempq;
		queries.push_back(tempq);
	}
	for(long long int query : queries)
	{
		b++;
		long long int i = 1;
		long long int num = query;
		long long int nextsub = 0;
		long long int sub = 1;
		long long int region = 1;
		long long nums;
		if (num <= 9)
		{
		}
		else
		{
			while (num > nextsub)
			{
				long long tempnum = num;
				sub = i * 9 * pow(10, i - 1);
				nextsub = i * 9 * pow(10, i);
				if (num - sub > 0)
				{
					num = num - sub;
					region++;
				}
				else
				{
					//cout << "nada" << endl;
				}
				//cout << "NUM: " << num << ", SUB: " << sub << endl;
				i++;
			}
		}
		//cout << "REGION: " << region << " NUMS: " << region * 9 * pow(10, region - 1) << endl;
		nums = region * 9 * pow(10, region - 1);
		long long calc = (num - 1) / region + pow(10, region - 1);
		//cout << "CALCULATION: " << calc << endl;
		string result = to_string(calc);
		long long pos = (num - 1) % region;
		//cout << "POS: "<< pos << endl;
		if (b < queries.size())
		{
			cout << result[pos] << endl;
		}
		else
		{
			cout << result[pos];
		}
	}
}