Codeforces Round 970 (Div. 3) 2008B. Square or Not Solution

 


                  

Problem Link
  :https://codeforces.com/contest/2008/problem/B

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. int n ; cin >> n ;
  11. string s ; cin >> s ;
  12. int cnt = 0 ;
  13. for (int i = 0 ; i < n ; i++){
  14. if(s[i] == '0'){
  15. break ;
  16. }
  17. else{
  18. cnt++;
  19. }
  20. }
  21. if(n == 4){
  22. if( cnt == n){
  23. cout <<"YES\n";
  24. }
  25. else{
  26. cout <<"NO\n";
  27. }
  28. }
  29. else {
  30. if( (cnt - 1 ) * (cnt - 1 ) == n){
  31. cout <<"YES\n";
  32. }
  33. else{
  34. cout <<"NO\n";
  35. }
  36. }
  37. }
  38. return 0 ;
  39. }

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.