[ create a new paste ] login | about

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

C++, pasted on Aug 7:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

#define N 21

int main(int argc, char* argv[])
{
	int A[N] = { 3, 5, 1, 4, 8, 7, 6, 5, 2, 4, 4, 1, 3, 0, 2, 8, 9, 7, 6, 4, 3 };

	printf("A = ");

	for (int t = 0; t < N; t++)
		printf("%d ",A[t]);
	
	printf("\n");

	int m = 0, x = 0; int B[N] = { 0 };
	for (int i = 0; m < N; i++, m+=3)
	{
		int len = (((N-m) < 3) ? (N-m) : 3);
		for (int k = m, j = 0; k < m + len; k++)
			for (int r = 0; r < N; r++)
				if (A[r] == k) B[x++] = A[r];
	}

	printf("B = ");

	for (int z = 0; z < N; z++)
		printf("%d ",B[z]);
	
	printf("\n");

	return 0;
}


Output:
1
2
A = 3 5 1 4 8 7 6 5 2 4 4 1 3 0 2 8 9 7 6 4 3 
B = 0 1 1 2 2 3 3 3 4 4 4 4 5 5 6 6 7 7 8 8 9 


Create a new paste based on this one


Comments: