[ create a new paste ] login | about

Link: http://codepad.org/zpQhJolI    [ raw code | output | fork ]

C++, pasted on Nov 14:
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

const int n = 20;
const int m = 10;

int main(int argc, char* argv[])
{
	int** A = new int*[n];
	memset((void*)A, 0x00, 4 * n);

	int* B = new int[n];
	memset((void*)B, 0x00, n * sizeof(int));

	for (int t1 = 0; t1 < n; t1++)
	{
		A[t1] = new int[m];
		memset((void*)A[t1], 0x00, sizeof(int) * m);
		
		B[t1] = rand() % (m-1) + 1;
		for (int t2 = 0; t2 < B[t1]; t2++)
			A[t1][t2] = rand() % m + 1;
	}

	for (int z1 = 0; z1 < n; z1++)
	{
		for (int z2 = 0; z2 < m; z2++)
			printf("%d ",A[z1][z2]);

		printf("\n");
	}

	printf("\n");

	int* T = new int[n*m];
	memset((void*)T, 0x00, sizeof(int)*n*m);

	int x = 0;
	for (int i = 0; i < n; i++)
		for (int k = 0; k < B[i]; k++)
			T[x++] = A[i][k];

	for (int r = 0; r < x; r++)
		printf("%d ",T[r]);

	printf("\n");

	return 0;
}


Output:
7 8 0 0 0 0 0 0 0 0 
4 6 7 3 10 2 3 8 0 0 
10 4 7 1 7 3 0 0 0 0 
2 9 0 0 0 0 0 0 0 0 
10 3 1 3 4 8 6 0 0 0 
3 3 9 10 8 4 0 0 0 0 
2 3 10 4 2 10 5 8 0 0 
5 6 1 4 7 2 0 0 0 0 
7 4 3 1 7 2 6 6 5 0 
7 6 7 10 4 8 5 0 0 0 
3 0 0 0 0 0 0 0 0 0 
5 0 0 0 0 0 0 0 0 0 
5 5 4 1 8 9 7 0 0 0 
9 5 4 2 5 10 3 1 7 0 
10 0 0 0 0 0 0 0 0 0 
7 7 0 0 0 0 0 0 0 0 
10 6 1 5 0 0 0 0 0 0 
8 2 0 0 0 0 0 0 0 0 
3 8 3 3 7 2 0 0 0 0 
7 2 6 0 0 0 0 0 0 0 

7 8 4 6 7 3 10 2 3 8 10 4 7 1 7 3 2 9 10 3 1 3 4 8 6 3 3 9 10 8 4 2 3 10 4 2 10 5 8 5 6 1 4 7 2 7 4 3 1 7 2 6 6 5 7 6 7 10 4 8 5 3 5 5 5 4 1 8 9 7 9 5 4 2 5 10 3 1 7 10 7 7 10 6 1 5 8 2 3 8 3 3 7 2 7 2 6 


Create a new paste based on this one


Comments: