Manna and Abraham Game

QUESTION

Manna is extremely disappointed to find out that no one in his college knows his first name. Even his classmates call him only by his last name. Frustrated, he decides to make his fellow college students know his first name by forcing them to solve this question.\n\nYou are given a long string as input in each testcase, containing any ASCII character. Your task is to find out the number of times SUVO and SUVOJIT appears in it.\n\nInput Format\nThe first line contains the number of testcases, T. Next, T lines follow each containing a long string S.\n\nOutput Format\nFor each long string S, display the no. of times SUVO and SUVOJIT appears in it.

“TESTCASE_1”: “5\nSUVOJITSUVOSUVOJITUCSUVOJITSUVOVXSUVOJITSUVOGMSUVODMMVDSUVOJIT\nAXRSUVOJITHSUVOJITHSUVOJJSUVOJITSUVOJIT\nSUVOJITPRQSUVOJIT\nSUVOJITTXGSUVOUNSUVOJIT\nSUVOJITSUVOSUVOJITXGSUVOSUVOQSUVOJITKDSALASUVOQESUVOHSSUVODFSUVOJITWSUVOUSUVOJITGJEM\n###—###SEPERATOR—###—\nSUVO=4, SUVOJIT=5\nSUVO=1, SUVOJIT=4\nSUVO=0, SUVOJIT=2\nSUVO=1, SUVOJIT=2\nSUVO=7, SUVOJIT=5”, “TESTCASE_2”: “3\nSUVOJITSU\n651SUVOMN\n$$$$$SUVOSUVOJIT$$$$$\n###—###SEPERATOR—###—\nSUVO=0, SUVOJIT=1\nSUVO=1, SUVOJIT=0\nSUVO=1, SUVOJIT=1”, “TESTCASE_3”: “10\nFSUVOFCOSUVOJITOSUVOAESUVOJITKBSUVOJITSUVOJITSUVOJITFCSUVOJITSUVOSUVOJIT\nSUVOTSUVOSUVOJITGSUVORSUVOSUVOQSUVOJITSUVOTSUVOTXXHYNPSUVO\nSUVOJITSUVO\nSUVOJITSUVORKTSUVOSUVOJITSUVOJITSUVOJITBYGISSUVOJITSUVOSUVOJITRSUVOHSUVO\nSUVOMSUVOSUVO\nWDKLQSUVOJITGSUVOSUVOSUVOJITDSESSUVOJITSUVOYAHY\nMQLSUVOJIT\nSUVOJITOJCSUVOJITVYRHGNLNOWOESUVOJITSUVOJITEYSUVO\nPMSUVOJITMRWJWBSUVOMSUVOXWSUVOJSUVOJIT\nSUVOJITAMSUVOJITONQRVVUQTASUVOJITSUVOJITNBWGQGQSUVORYJRRSUVOJIT\n###—###SEPERATOR—###—\nSUVO=3, SUVOJIT=7\nSUVO=8, SUVOJIT=2\nSUVO=1, SUVOJIT=1\nSUVO=5, SUVOJIT=6\nSUVO=3, SUVOJIT=0\nSUVO=3, SUVOJIT=3\nSUVO=0, SUVOJIT=1\nSUVO=1, SUVOJIT=4\nSUVO=3, SUVOJIT=2\nSUVO=1, SUVOJIT=5”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int countSubstring(const std::string& str, const std::string& sub)
{
    if (sub.length() == 0) return 0;
    int count = 0;
    for (size_t offset = str.find(sub); offset != std::string::npos;
     offset = str.find(sub, offset + sub.length()))
    {
        ++count;
    }
    return count;
}

int main()
{
    int testCases,suvo,suvojit;
    cin>>testCases;
    while(testCases--)
    {
        string name;
        cin>>name;
        suvo = countSubstring(name,"SUVO");
        suvojit = countSubstring(name,"SUVOJIT");
        cout<<"SUVO="<<suvo-suvojit<<", SUVOJIT="<<suvojit<<"\n";
    }
    return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.