#include "stdafx.h"//del
#include <iostream>
#include <string>
using namespace std;
void print(string name, int len, int * pMas)
{
cout << endl;
cout <<name << "={";
for (int i = 0; i < len; i++)
{
cout << pMas[i];
if (i == (len - 1)) cout << "}";
else
cout << ",";
}
cout << endl;
}
int main()
{
int lenMasK = 0;
cout << "Len= ";
cin >> lenMasK;
int *pMas;
pMas = (int *)malloc(lenMasK * sizeof(int));
for (int i = 0; i < lenMasK; i++)
{
cout << "K[" << i << "]=";
cin >> pMas[i];
}
print("K", lenMasK, pMas);
int *pR;
pR = (int *)malloc(lenMasK * sizeof(int));
pR[0] = pMas[0];
int lenRes = 1;
for (int i = 0; i < (lenMasK-1); i++)
if (pMas[i] != pMas[i+1])
{
pR[lenRes] = pMas[i+1];
lenRes++;
}
print("K'", lenRes, pR);
free(pMas);
free(pR);
system("pause");
cout << endl;
return 0;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.