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

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 &g...

Powered by Blogger.