fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <string.h>
  4. #include <vector>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <cmath>
  8. #include <vector>
  9. #include <iomanip>
  10. #include <climits>
  11. #include <bits/stdc++.h>
  12. #define ll long long
  13. using namespace std;
  14. int main() {
  15. ios::sync_with_stdio(false);
  16. cin.tie(NULL);
  17.  
  18. int n;
  19. cin >> n;
  20. vector<string> s(n);
  21.  
  22. for (int i = 0; i < n; i++) {
  23. cin >> s[i];
  24. }
  25. string maxi = s[0];
  26. for (int i = 1; i < n; i++) {
  27. int j = 0;
  28. while (j <maxi.size()&&j<s[i].size()&&maxi[j]== s[i][j]) {
  29. j++;
  30. }
  31. maxi =maxi.substr(0, j);
  32.  
  33. }
  34.  
  35.  
  36. int op = 0;
  37. for (int i = 0; i < n; i++) {
  38. op+= (s[i].size() -maxi.size());
  39. }
  40.  
  41. cout << op<< endl;
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
0