Given a string, count all distinct substrings of the given string.
Example
Input
abcd
Output
10
All Elements are Distinct
Input
aaa
Output
6
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include<bits/stdc++.h>
using namespace std;
int distinctSubstring(string str)
{
set<string> res ;
for (int i = 0; i <= str.length(); i++)
{
for (int j = i + 1; j <= str.length(); j++)
{
res.insert(str.substr(i, j));
}
}
return res.size();
}
int main()
{
string str;
cin>>str;
cout << (distinctSubstring(str));
}
#include
using namespace std;
int main()
{
string g;
int len,i,sum;
cin>>g;
len=g.length();
sum=0;
for (i=len;i>0;i–)
{
sum+=i;
}
cout<<sum<<endl;
return 0;
}