Help me in solving SPOON problem

My issue

My code

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	std::cin >> t;
	while(t--)
	{
	    int n,m;
	    cin>>n>>m;
	    string str;
	    for(int i=0;i<n;i++)
	    {
	        string s;
	        cin>>s;
	        for(int i=0;i<s.size();i++)
	        {
	            
	            s[i]=tolower(s[i]);
	        }
	        for(int i=0;i<s.size();i++)
	        {
	            
	            if( s[i]=='s'|| s[i]=='p' ||s[i]=='o' ||s[i]=='n')
	            {
	                str+=s[i];
	            }
	        }
	    }
	        string target="spoon";
	        auto it = search(str.begin(), str.end(), target.begin(), target.end());
	        if( it!=str.end())std::cout << "There is a spoon!" << std::endl;
	        else std::cout << "There is indeed no spoon!" << std::endl;
	        str.clear();
	    
	}
	return 0;
}

Problem Link: SPOON Problem - CodeChef

@pranto1610
u have to find spoon as a substring not subsequence and also u have to check it both horizontal and vertical order.

1 Like