In this HackerEarth DifDif problem solution, You are given a string S. Find the number of different substrings in S.


HackerEarth DifDif problem solution


HackerEarth DifDif problem solution.

#include<bits/stdc++.h>

using namespace std;
 
string st;
set<long long> ans;
 
int main(){

cin>>st;

for (int i=0;i<st.size();i++)
{
    long long s=0;
    for (int j=i;j<st.size();j++)
    {
        s=s*173+st[j];
        ans.insert(s);
    }
}

cout<<ans.size()<<endl;

return 0;}