Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<vector>
- #include<algorithm>
- using namespace std;
- int ten(int x)
- {
- int tn = 0;
- if(x == 1) tn = 1;
- else if ( x == 2) tn = 11;
- else if ( x == 3) tn = 111;
- else if ( x == 4) tn = 1111;
- else if ( x == 5) tn = 11111;
- else if ( x == 6) tn = 111111;
- else if ( x == 7) tn = 1111111;
- else if ( x == 8) tn = 11111111;
- else if ( x == 9) tn = 111111111;
- else if ( x == 10) tn =1111111111;
- return tn;
- }
- int main()
- {
- int k;
- cin>>k;
- vector<int>ans;
- for(int i = 0; i < k; i++)
- {
- int n;
- cin>>n;
- vector<int>v;
- int f = n;
- while(f!=0)
- {
- v.push_back(f%10);
- f/=10;
- }
- reverse(v.begin(), v.end());
- int res = n/ten(v.size()) + 9*(v.size() - 1);
- ans.push_back(res);
- }
- for(int i = 0; i < ans.size(); i++)
- {
- cout<<ans[i]<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement