Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctype.h>
  3. #define Maxlength 100
  4. using namespace std;
  5. bool isdigit(char c) {
  6. return (c <= '9' && c >= '0');
  7. }
  8. char Strcpy(char &str_copy, char str);
  9. char Strcpy(char &str_copy, char str) {
  10. str_copy = str;
  11. return str_copy;
  12. }
  13. int main()
  14. {
  15.  
  16. char str[Maxlength + 1];
  17. cin.get(str, Maxlength + 1);
  18.  
  19.  
  20.  
  21. //<ctype.g>
  22.  
  23. int len = strlen(str);
  24.  
  25. char **mas_str = new char*[len + 1];
  26. char *str_copy = new char[len + 1];
  27.  
  28. Strcpy(*str_copy, str);
  29.  
  30. int i = 0, m, k = 0;
  31.  
  32. while (i < len) {
  33. while (!isdigit(str[i]) && i < len) i++;
  34. if (i < len)
  35. {
  36. mas_str[k++] = &str[i];
  37. while (isdigit(str[i])) i++;
  38. str[i] = '\0';
  39. }
  40. }
  41.  
  42. if (k > 0) {
  43. for (int i = 0; i < k; i++)
  44. cout << mas_str[i] << endl;
  45.  
  46. for (int i = 0; i < k; i++) {
  47. for (int j = 0; j < k - i - 1; j++)
  48. if (strlen(mas_str[j]) > strlen(mas_str[j + 1])) {
  49. swap(mas_str[j], mas_str[j + 1]);
  50.  
  51.  
  52. //posle sortirovki
  53. for (int i = 0; i < k; i++)
  54. cout << mas_str[i] << endl;
  55.  
  56. int sum = 0;
  57. for (int i = 0; i < k; i++)
  58. sum += atoi(mas_str[i]);
  59.  
  60. cout << sum << endl;
  61. }
  62. else {
  63. cout << "there is no nums" << endl;
  64. }
  65. }
  66. return 0;
  67.  
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement