fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int N, M, i, j;
  7. int max = 0;
  8. do {
  9. cout << "Enter the number of vertices and the number of edges: \n";
  10. cin >> N >> M;
  11. } while (N <= 1 || N >= 50 && M <= 1 || M >= 500);
  12. cout << "Enter the matrix : \n";
  13.  
  14. int** mass = new int* [N];
  15. for (int i = 0; i < N; i++)
  16. mass[i] = new int[M];
  17.  
  18. for (i = 0; i < N; i++)
  19. {
  20. for (j = 0; j < M; j++)
  21. {
  22. cin >> mass[i][j];
  23. }
  24. }
  25.  
  26. cout << "\n";
  27.  
  28.  
  29. int ones[2], cnt, A[50][50];
  30.  
  31. for (int i = 0; i < N; i++)
  32. {
  33. for (int j = 0; j < N; j++)
  34. {
  35. A[i][j] = 0;
  36. }
  37. }
  38.  
  39. for (i = 0; i < M; i++)
  40. {
  41. cnt = 0;
  42. for (j = 0; j < N; j++)
  43. {
  44. if (mass[j][i] == 1)
  45. {
  46. ones[cnt++] = j;
  47. }
  48. }
  49. A[ones[0]][ones[1]] = 1;
  50. A[ones[1]][ones[0]] = 1;
  51. }
  52.  
  53. for (int i = 0; i < N; i++)
  54. {
  55. for (int j = 0; j < N; j++)
  56. cout << A[i][j] << " ";
  57. cout << endl;
  58. }
  59.  
  60. cout << "\n";
  61. system("pause");
  62. return 0;
  63. }
Success #stdin #stdout #stderr 0s 4520KB
stdin
3
2
1 0
1 1
0 1
stdout
Enter the number of vertices and the number of edges: 
Enter the matrix : 

0 1 0 
1 0 1 
0 1 0 

stderr
sh: 1: pause: not found