fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5. vector<string> a;
  6.  
  7. void ExtractNum(const string& s) {
  8. string num = "";
  9. for (int i = 0; i < s.length(); i++)
  10. if ((s[i] >= '0') && (s[i] <= '9'))
  11. num += s[i];
  12. else if (num != "") {
  13. a.push_back(num);
  14. num = "";
  15. }
  16. }
  17.  
  18. void Input() {
  19. int n; string s;
  20. cin >> n;
  21. getline(cin, s);
  22. for (int i = 0; i < n; i++) {
  23. getline(cin, s);
  24. s += 'a';
  25. ExtractNum(s);
  26. }
  27. }
  28.  
  29. void AddZeros() {
  30. int maxdigits = 0;
  31. for (int i = 0; i < a.size(); i++)
  32. maxdigits = max(maxdigits, (int)a[i].length());
  33. for (int i = 0; i < a.size(); i++)
  34. for (int j = 1; j <= maxdigits - a[i].length(); j++)
  35. a[i] = '0' + a[i];
  36. }
  37.  
  38. void Sort() {
  39. string t;
  40. for (int i = 0; i < a.size(); i++)
  41. for (int j = i + 1; j < a.size(); j++)
  42. if (a[i] > a[j]) {
  43. t = a[i]; a[i] = a[j]; a[j] = t;
  44. }
  45. }
  46.  
  47. void TrimZeros() {
  48. for (int i = 0; i < a.size(); i++)
  49. while ((a[i].length > 1) && (a[i][0] == '0'))
  50. a[i].erase(0, 1);
  51. }
  52.  
  53. void Output() {
  54. for (int i = 0; i < a.size(); i++) {
  55. cout << a[i] << endl;
  56. }
  57. }
  58.  
  59. int main() {
  60. Input();
  61. AddZeros();
  62. Sort();
  63. TrimZeros();
  64. Output();
  65. return 0;
  66. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
2
l03az4
01
compilation info
prog.cpp: In function 'void TrimZeros()':
prog.cpp:49: error: invalid use of member (did you forget the '&' ?)
stdout
Standard output is empty