ChameL1oN

Пересдача_Задача4

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