Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
team name
//g++ 7.4.0 #include <bits/stdc++.h> using namespace std; typedef long long int ll; ll permutation(ll n, ll k) { ll fact[n + 1]; // Base case fact[0] = 1; // Calculate value // factorials up to n for(ll i = 1; i <= n; i++) fact[i] = i * fact[i - 1]; // P(n,k) = n! / (n - k)! return fact[n] / fact[n - k]; } int main() { int t; cin >> t; while(t--){ int n; cin >> n; vector<string> v(n); for(int i=0;i<n;i++) cin >> v[i]; unordered_set<string> st; int count = 0; for(int i=0;i<n;i++) st.insert(v[i]); for(int i=0;i<n;i++){ string temp = v[i]; for(int j=0;j<n;j++){ string test = v[j]; string key = temp[0] + test.substr(1, test.size()-1); if (st.find(key) == st.end()){ count++; st.insert(key); } else continue; } } cout << permutation(count, 2) << endl; } }
run
|
edit
|
history
|
help
0
Adress
Peg Grammar Parser Grasshopper Language
BintTree vertical sum
dia
MoveBubble
queueArray
Switch case
Trapping rain water problem
ClassQuiz
Virtuals