fork download
  1. #include<iostream>
  2. #include<string>
  3. #include<cstdlib>
  4. #include<algorithm>
  5. using namespace std;
  6. string s1="hackerrank";
  7. int main()
  8. {
  9. int N,i=0;
  10. cin>>N;
  11. do
  12. {
  13. string s;
  14. getline(cin,s);
  15. unsigned int k=s.find(s1);
  16. unsigned int k1=s.rfind(s1);
  17. if(k==0 && k1==(s.length()-10))
  18. cout<<"0"<<endl;
  19. else if(k==0)
  20. cout<<"1"<<endl;
  21. else if(k1==(s.length()-10))
  22. cout<<"2"<<endl;
  23. else
  24. cout<<"-1"<<endl;
  25. i++;
  26. }while(i<=N);
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 15240KB
stdin
4
i love hackerrank
hackerrank is an awesome place for programmers
hackerrank
i think hackerrank is a great place to hangout
stdout
-1
2
1
0
-1