Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
codejam1a1
#include<bits/stdc++.h> using namespace std; string cop(string str1, string str2) { string result; int n1 = str1.length(), n2 = str2.length(); for (int i=0, j=0; i<=n1-1&&j<=n2-1; i++,j++) { if (str1[i] != str2[j]) break; result.push_back(str1[i]); } return (result); } int main(){ int t;cin>>t; for(int tt = 1;tt < t+1;tt++){ int n;cin>>n; vector<string> v; string s; for(int i = 0;i < n;i++){ cin>>s; reverse(s.begin(),s.end()); v.push_back(s); } sort(v.begin(),v.end()); int c = 0,len1 = 100,len2 = 100; string pre1 = "",pre2 = ""; for(int i = 0,j = 1,f = 0;j < n;i+=2,j+=2){ while(true){ if(j < n && i < n && v[i][0]!=v[j][0] ){ i = j;j = j+1; } else break; } if(j >=n) break; pre2 = cop(v[i],v[j]); if(pre2!=pre1){ c++; pre1 = pre2; len1 = pre1.length(); } else{ len2 = len1 - 1; if(len2 > 0){ c++; len1--; } else{ len2 = 0; } } } cout<<"Case #"<<tt<<": "<<c*2<<"\n"; } return 0; }
run
|
edit
|
history
|
help
0
1 through 1000
hhhh
1.1 Basics: language constructs
deletevowels
jjj4
Reverse And Shift Char in String
V
масиви форіч
Trabalho
little problem