forked from Shubhamlmp/Programming-Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMincostString.cpp
48 lines (41 loc) · 1.11 KB
/
MincostString.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef map<ll,ll> ml;
typedef vector<char> vc;
typedef vector<double> vdb;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<vector<ll>> vvl;
typedef pair<int, int> pi; //inserting values: pi = make_pair(3,2); printing values: cout<<pi.first<<" "<<pi.second;
typedef vector<pair<ll,ll>> vp;
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
#define loop(i,x,n) for(ll i=x;i<=n;i++)
#define rloop(i,x,n) for(ll i=x;i>=n;i--)
#define fill(a,b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define mod 1000000007
int minCost(string& s)
{
// Initially all characters are un-seen
bool alphabets[26] = { false };
// Marking seen characters
for (int i = 0; i < s.size(); i++)
alphabets[s[i] - 97] = true;
// Count total seen character, and that
// is the cost
int count = 0;
for (int i = 0; i < 26; i++)
if (alphabets[i])
count++;
return count;
}
int main()
{
string s;
cin>>s;
cout << "Cost to construct :"
<< s << " is " << minCost;
return 0;
}