Codeforces 1462B - Last Year's Substring Solution

 Solution in C++:

///**********ALLAH IS ALMIGHTY************///

///AH Tonmoy

///Department of CSE,23rd batch

///Islamic University,Bangladesh  

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t,n,i,j,f;
  6. cin>>t;
  7. while(t--)
  8. {
  9. string s;
  10. cin>>n>>s;
  11. if((s.substr(0,4)=="2020")||(s.substr(n-4,4)=="2020"))
  12. cout<<"YES"<<endl;
  13. else if((s.substr(0,2)=="20")&&(s.substr(n-2,2)=="20"))
  14. cout<<"YES"<<endl;
  15. else if((s.substr(0,3)=="202")&&(s.substr(n-1,1)=="0"))
  16. cout<<"YES"<<endl;
  17. else if((s[0]=='2')&&(s.substr(n-3,3)=="020"))
  18. cout<<"YES"<<endl;
  19. else
  20. cout<<"NO"<<endl;
  21. }
  22. }
  23.  

No comments

Most View Post

Recent post

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.