Advertisement
Guest User

Spoj - Wiatraczki 3 pkt

a guest
Sep 12th, 2021
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.85 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     string napis;
  9.     int pomocnicza;
  10.     int ile,ile2,liczba;
  11.  
  12.     while(true)
  13.     {
  14.         cin>>ile2;
  15.         ile=abs(ile2);
  16.         pomocnicza=2*ile-1;
  17.  
  18.         if (ile2==0)
  19.         {
  20.             exit(0);
  21.         }
  22.         else if (ile2<0)
  23.         {
  24.             for(int i=0; i<=pomocnicza; i++)
  25.             {
  26.                 napis="";
  27.                 for(int j=0; j<=pomocnicza; j++)
  28.                 {
  29.                     if(i==j)
  30.                     {
  31.                         napis+="*";
  32.                     }
  33.                     else if(i==(pomocnicza-j))
  34.                     {
  35.                         napis+="*";
  36.                     }
  37.                     else if ((i<j)&&(j<=(pomocnicza/2)))
  38.                     {
  39.                         napis+="*";   //Obszar 1
  40.                     }
  41.                     else if ( ((i+j)>pomocnicza) && (i<=(pomocnicza/2)) &&(j>=ile) )
  42.                     {
  43.                         napis+="*";   //Obszar 3
  44.                     }
  45.                     else if ((i>j)&&(j>=ile))
  46.                     {
  47.                         napis+="*";   //Obszar 5
  48.                     }
  49.                     else if( ((i+j)<pomocnicza) && (i>=ile) && (j<=(pomocnicza/2)) )
  50.                     {
  51.                         napis+="*";   //Obszar 7
  52.                     }
  53.                     else
  54.                     {
  55.                         napis+=".";
  56.                     }
  57.                 }
  58.                 cout<<napis<<endl;
  59.             }
  60.         }
  61.         else
  62.         {
  63.             for(int i=0; i<=pomocnicza; i++)
  64.             {
  65.                 napis="";
  66.                 for(int j=0; j<=pomocnicza; j++)
  67.                 {
  68.                     if(i==j)
  69.                     {
  70.                         napis+="*";
  71.                     }
  72.                     else if(i==(pomocnicza-j))
  73.                     {
  74.                         napis+="*";
  75.                     }
  76.                     else if ( ((i+j)<pomocnicza) && (i<=(pomocnicza/2)) &&(j>=ile) )
  77.                     {
  78.                         napis+="*";   //Obszar 2
  79.                     }
  80.                     else if ( (i<j) && (i>=ile) && (j>=ile) )
  81.                     {
  82.                         napis+="*";   //Obszar 4
  83.                     }
  84.                     else if ( (j<(pomocnicza/2)) && ((i+j)>pomocnicza) )
  85.                     {
  86.                         napis+="*";   //Obszar 6
  87.                     }
  88.                     else if( (i<=(pomocnicza/2)) && (j<=(pomocnicza/2)) && i>j  )
  89.                     {
  90.                         napis+="*";   // Obszar 8
  91.                     }
  92.                     else
  93.                     {
  94.                         napis+=".";
  95.                     }
  96.                 }
  97.                 cout<<napis<<endl;
  98.             }
  99.         }
  100.     }
  101.     return 0;
  102. }
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement