ChameL1oN

Экзамен_Задача3

Dec 21st, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <locale>
  4. using namespace std;
  5.  
  6. ifstream f("ishod.txt", ios::in);
  7.  
  8. bool function(int a){
  9. int b;
  10. bool posl = true;
  11. b = a % 10;
  12. a /= 10;
  13. while (a > 0){
  14. if (a % 10 >= b){
  15. posl = true;
  16. b = a % 10;
  17. }
  18. else{
  19. posl = false;
  20. break;
  21. }
  22. a /= 10;
  23. }
  24. return posl;
  25. }
  26.  
  27. int* form_mas(int a){
  28. int b = 0;
  29. int* massive = new int[a];
  30. for (int i = 0; i < a; i++){
  31. f >> b;
  32. massive[i] = b;
  33. }
  34. return massive;
  35. }
  36.  
  37. void main(){
  38.  
  39. setlocale(LC_ALL, "rus");
  40. int a,i;
  41. f >> a;
  42. int* mass = form_mas(a);
  43. cout << "Исходный массив : " << endl;
  44. for (i = 0; i < a; i++){
  45. cout << mass[i] << endl;
  46. }
  47. cout << endl;
  48. for (int k = a - 1; k>-1; k--){
  49. if (function(mass[k]))
  50. {
  51. for (i = k; i < a - 1; i++)
  52. mass[i] = mass[i + 1]; // a[i] – указывает, куда сдвигаем
  53. a--;
  54. }
  55. }
  56.  
  57. cout << "Массив после обработки" << endl;
  58. cout << endl;
  59. for (i = 0; i < a; i++){
  60. cout << mass[i] << endl;
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment