Codeforces 1216E1. Numerical Sequence (easy version) Solution

Solve in       C++:

///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE
///Islamic University,Bangladesh
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. int main()
  5. {
  6. long long t;
  7. cin>>t;
  8. while(t--)
  9. {
  10. long long n,v=0;
  11. cin>>n;
  12. string s;
  13. while(1)
  14. {
  15. v++;
  16. string s1 = to_string(v);
  17. s+=s1;
  18. if(n>s.length())
  19. n-=s.length();
  20. else
  21. {
  22. cout << s[n-1]<<endl;
  23. break;
  24. }
  25.  
  26. }
  27.  
  28. }
  29.  
  30. return 0;
  31. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.