Codeforces 1512A. Spy Detected! Solution

  Solution in C++: 

///******Bismillahir-Rahmanir-Rahim******///

///AH Tonmoy

///Department of CSE,23rd batch

///Islamic University,Bangladesh 

  1. #include <iostream>
  2. using namespace std;
  3. int fda(int ar[],int n)
  4. {
  5.  
  6. if (n == 1)
  7. return -1;
  8. if (n == 2)
  9. return 0;
  10. if (ar[0] == ar[1] && ar[0] != ar[2])
  11. return 2;
  12. if (ar[0] == ar[2] && ar[0] != ar[1])
  13. return 1;
  14. if (ar[1] == ar[2] && ar[0] != ar[1])
  15. return 0;
  16. for (int i = 3; i < n; i++)
  17. if (ar[i] != ar[i - 1])
  18. return i;
  19.  
  20. return -1;
  21. }
  22. int main()
  23. {
  24. int j,tst,n;
  25. cin>>tst;
  26. while(tst--)
  27. {
  28. cin>>n;
  29. int ar[n+9];
  30. for(int j=0; j<n; j++)
  31. {
  32. cin>>ar[j];
  33. }
  34. cout << fda(ar,n)+1<<endl;
  35.  
  36. }
  37. return 0;
  38. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

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

Powered by Blogger.