Jump to content
Forum Roportal
Sign in to follow this  
Ady_add_me

programare c++ sau java

Rate this topic

Recommended Posts

Va rog sa ma ajutati sa rezolv si eu o problema in c++ sau java.Am poimaine de prezentat un programul . Dati-mi va rog macar o idee...

Problema suna in felul urmator:

 

Pentru un numar natural n dat sa se genereze intr-o matrice patratica de dimensiune 3n un octagon care sa contina numerele naturale consecutive 1,2,3,

Share this post


Link to post
Share on other sites

Am rezolvat problema. "Sper sa iti fie de folos", e in C++.:

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

typedef int _;
typedef size_t __;
typedef void ___;
#define ____(x) ((x)++)
#define _____(x) ((x)--)
#define X {
#define XX }

___ *_00(__ _, __ __);_ **_01(_ n);___ _10(_ **mat, _ n);___ _11(_ **mat, _ n);
___ *_00(__ _$, __ _$$) X ___ *_$$$ = (___*) 0;if (!(_$$$ = calloc(_$, _$$)))
exit(-1);return _$$$; XX _ **_01(_ n) X _ **_$$$$ = (___*) 0, _0, _$$$$$ = 3
* n;_$$$$ = _00(_$$$$$, sizeof (_*)); for (_0 = 0; _0 < _$$$$$; ____(_0))
*(_$$$$ + _0) = _00(_$$$$$, sizeof (_));return (_$$$$);XX ___ _10(_ **_8, _
_9) X _ _1 = 1, _2 = (3 * _9 - 1), _3 = 2 * _9 - 1, _4 = 2 * _9 * (3 * _9 - 1),
_5 = 0; _ _6 = -1, _7 = _9 * _9;while (_____(_4) > 0) X *(*(_8 + _2) + _3) =
____(_1);if (_2 >= 0 && _2 < _9) X if (_3 >= 0 && _3 < _9) X ____(_3);_____(_2);
XX else if (_3 >= _9 && _3 < 2 * _9) X if (_3 == 2 * _9 - 1) ____(_2);____(_3);
XX else if (_3 >= 2 * _9 && _3 < 3 * _9) X ____(_3);____(_2);XX XX else if (_2
>= _9 && _2 < 2 * _9) X if (_3 >= 0 && _3 < _9) X if (_2 == _9) ____(_3);
_____(_2); XX else if (_3 >= 2 * _9 && _3 < 3 * _9) X if (_2 == 2 * _9 - 1)
_____(_3);____(_2); XX XX else if (_2 >= 2 * _9 && _2 < 3 * _9) X if (_3 > 0 &&
_3 < _9) X _____(_2);_____(_3); XX else if (_3 >= _9 && _3 < 2 * _9) X if (_3 ==
_9) _____(_2);_____(_3); XX else if (_3 >= 2 * _9 && _3 < 3 * _9) X ____(_2);
_____(_3);XX XX if (*(*(_8 + _2) + _3)) _____(_2);XX _2 = 2 * _9 - 1;_3 = 2 * _9
- 1;while (_____(_7) > 0) X *(*(_8 + _2) + _3) = ____(_1);if (*(*(_8 + _2 + _5)
+ _3 + _6)) X if (!_5 && _6 == -1) X _5 = -1;_6 = 0; XX else if (_5 == -1 &&
!_6) X _5 = 0;_6 = 1;XX else if (!_5 && _6 == 1) X _5 = 1;_6 = 0;XX else if (_5
== 1 && !_6) X _5 = 0;_6 = -1;XX XX _2 += _5;_3 += _6; XX XX ___ _11(_ **_8,
_ _9) X _ i, j, _11;_11 = 3 * _9;for (i = 0; i < _11; ____(i)) X for (j = 0; j <
_11; ____(j)) printf("%5d", *(*(_8 + i) + j));printf("\n"); XX XX

_ main() {
_ **_8;_ _N;

printf("Introduce dimensiunea n (n>=2):\n");
scanf("%d",&_N);

_8 = _01(_N);_10(_8, _N);_11(_8, _N);
return (0);
}

 

Dupa compilare:

 

Introduce dimensiunea n (n>=2):
4
0	0	0	0   15   16   17   18	0	0	0	0
0	0	0   14   41   42   43   44   19	0	0	0
0	0   13   40   63   64   65   66   45   20	0	0
0   12   39   62   81   82   83   84   67   46   21	0
  11   38   61   80   95   96   97   98   85   68   47   22
  10   37   60   79   94  103  104   99   86   69   48   23
9   36   59   78   93  102  101  100   87   70   49   24
8   35   58   77   92   91   90   89   88   71   50   25
0	7   34   57   76   75   74   73   72   51   26	0
0	0	6   33   56   55   54   53   52   27	0	0
0	0	0	5   32   31   30   29   28	0	0	0
0	0	0	0	4	3	2	1	0	0	0	0

 

Sau dupa cum se spunea mai sus te-ai putea folosi de ideea de cercuri concentrice: http://en.wikipedia.org/wiki/Midpoint_circle_algorithm

Edited by Nomemory

Share this post


Link to post
Share on other sites
Am rezolvat problema. "Sper sa iti fie de folos", e in C++.:

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
....}

 

Super fain codul, e pe intelesul tuturor. :D)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×