Advertisement
Guest User

Atestat(18)

a guest
Oct 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream in("linie.in");
  7. ofstream out("linie.out");
  8.  
  9. void citire(int a[50][50], int &n)
  10. {
  11.     in>>n;
  12.     for(int i=1; i<=n; i++)
  13.         for(int j=1; j<=n; j++)
  14.             in>>a[i][j];
  15. }
  16.  
  17. bool Prim(int x)
  18. {
  19.     if(x<2)
  20.         return false;
  21.     for(int i=2; i*i<=x; i++)
  22.         if(x%i==0)
  23.             return false;
  24.     return true;
  25. }
  26.  
  27. int Linie(int a[50][50], int n, int l)
  28. {
  29.     int nr=0;
  30.     for(int i=1; i<=n; i++)
  31.     {
  32.         if(Prim(a[l][i]) == true)
  33.             nr++;
  34.     }
  35.     return nr;
  36. }
  37.  
  38. void Rezolvare(int a[50][50], int n)
  39. {
  40.     int maxx=0,l=0, c;
  41.  
  42.     for(int i=1; i<=n; i++){
  43.         c = Linie(a, n, i);
  44.         if(c > maxx)
  45.         {
  46.             maxx = Linie(a, n, i);
  47.             l = i;
  48.         }
  49.     }
  50.     out<<l<<'\n';
  51. }
  52.  
  53. void DP(int a[50][50], int n)
  54. {
  55.     for(int i=1; i<=n; i++)
  56.         out<<a[i][i]<<' ';
  57. }
  58.  
  59. int main()
  60. {
  61.     int a[50][50], n;
  62.  
  63.     citire(a,n);
  64.     Rezolvare(a,n);
  65.     DP(a,n);
  66.  
  67.    
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement