Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. using namespace std;
  5. int ten(int x)
  6. {
  7.     int tn = 0;
  8.     if(x == 1) tn = 1;
  9.    else if ( x == 2) tn = 11;
  10.    else if ( x == 3) tn = 111;
  11.    else if ( x == 4) tn = 1111;
  12.    else if ( x == 5) tn = 11111;
  13.    else if ( x == 6) tn = 111111;
  14.    else if ( x == 7) tn = 1111111;
  15.    else if ( x == 8) tn = 11111111;
  16.    else if ( x == 9) tn = 111111111;
  17.    else if ( x == 10) tn =1111111111;
  18.  
  19.  
  20.  
  21.  
  22.     return tn;
  23. }
  24. int main()
  25. {
  26.     int k;
  27.     cin>>k;
  28.     vector<int>ans;
  29.     for(int i = 0; i < k; i++)
  30.     {
  31.  
  32.  
  33.     int n;
  34.     cin>>n;
  35.     vector<int>v;
  36.     int f = n;
  37.     while(f!=0)
  38.     {
  39.         v.push_back(f%10);
  40.         f/=10;
  41.     }
  42.     reverse(v.begin(), v.end());
  43.     int res = n/ten(v.size()) + 9*(v.size() - 1);
  44.     ans.push_back(res);
  45.  
  46.     }
  47.     for(int i = 0; i < ans.size(); i++)
  48.     {
  49.         cout<<ans[i]<<endl;
  50.     }
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement