Advertisement
Guest User

10th task

a guest
Sep 18th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5.  
  6. int main() {
  7.     FILE* input = fopen("input.txt", "r");
  8.     FILE* output = fopen("output.txt", "w");
  9.     int k = 0, answer = 0;
  10.     int am_num = 9, am_ch = 1;
  11.  
  12.     fscanf(input, "%d", &k);
  13.     while (1) {
  14.         if (k > am_num * am_ch) {
  15.             k -= am_num * am_ch;
  16.             am_num *= 10;
  17.             am_ch++;
  18.         }
  19.         else {
  20.             answer = pow(10, am_ch - 1);
  21.             int temp = k / am_ch;
  22.             if (k - temp * am_ch == 0) {
  23.                 answer += temp - 1;
  24.                 k = am_ch;
  25.             }
  26.             else {
  27.                 answer += temp;
  28.                 k %= am_ch;
  29.             }
  30.             break;
  31.         }
  32.     }
  33.     while (am_ch > k) {
  34.         answer /= 10;
  35.         am_ch--;
  36.     }
  37.     fprintf(output, "%d", answer % 10);
  38.     fclose(input);
  39.     fclose(output);
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement