Advertisement
anon20016

1

Dec 12th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <vector>
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. int n;
  11. cin >> n;
  12. vector<string> a(n);
  13. for (int i = 0; i < n; i++) {
  14. cin >> a[i];
  15. }
  16. int sum = 0;
  17.  
  18. // сортировка методом пузырька
  19. for (int j = 0; j < n; j++) {
  20. for (int i = 0; i < n - 1; i++) {
  21. // сравнение двух строк
  22. if (a[i].size() > a[i + 1].size()) {
  23. string t = a[i];
  24. a[i] = a[i + 1];
  25. a[i + 1] = t;
  26. }
  27. else {
  28. if (a[i].size() == a[i + 1].size()) {
  29. for (int q = a[i].size() - 1; q >= 0; q--) {
  30. if (a[i][q] > a[i + 1][q]) {
  31. string t = a[i];
  32. a[i] = a[i + 1];
  33. a[i + 1] = t;
  34. }
  35. }
  36. }
  37. }
  38. }
  39. }
  40. for (int i = 0; i < n; i++) {
  41. // перевод в 10ую систему исчисления
  42. int st = 1;
  43. for (int j = a[i].size() - 1; j >= 0; j--) {
  44. sum += (a[i][j] - '0') * st;
  45. st = st * 2;
  46. }
  47. cout << a[i] << ' ';
  48. }
  49. cout << endl << sum;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement