1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
#include <iostream>
#include <vector>
#include <fstream>
/* given an array of 50 numbers, dived the positions by five..
so we assume a position one or zero after every five numbers, the
aim here is to take the first two numbers after every five count, but on the condition
that the first two numbers of every five position count taken must not have values which repeat..
if there is a value repeating, then we go and look at the the third position of every five count,
making sure the value there is not in the group of first two of every five count, we replace a repetive number
with one of the values of the group of third positon of every five count...all in order!
Ist group: vector<int>cont == first two values of every five count
2nd group: vector<int>cont1 == third values of every five count
3rd group: vector<int>cont3 == Ist group with repetitive numbers replaced by values of 2nd group
don't look at the struct much, i had wanted to load some values in a linked list but i changed idea..
*/
const int arr [50]={
2,34,32,34,56,
76,87,98,3,4,
3,4,3,4,5,6,
7,55,67,65,67,
6,57,12,45,34,
59,67,57,4,34,
33,45,67,87,98
,38,45,65,23,12,
12,32,35,76,87,
45,82,98,78,};
struct Nodo
{ int valore;
Nodo *nextPtr;
};
Nodo * testa = 0;
int vll, y = 0;
void putinorder ( const int * pt1, const int * pt2);
void replace ();
void add_value();
void print_on_screen(std::vector<int>);
void write_to_file (std::vector<int>);
void inserimento(Nodo * &testa, int numero);
std:: vector <int> cont;
std:: vector <int> cont2;
std:: vector <int> cont3;
std:: vector<int>::iterator chk1 ;
std::vector<int>::iterator chk2;
std::vector<int>::iterator pt3 = cont2.begin();
int main()
{
putinorder(&arr[0], &arr[49]);
print_on_screen(cont3);
write_to_file (cont3);
return 0;
}
void putinorder ( const int * pt1, const int * pt2)
{
int y = 0, v0 = 0, v1=1, v2=2, v5=5, v6=6, v7=7, v10=10, v11=11, v12=12, v15=15, v16=16, v17=17;
int v20= 20, v21=21, v22=22, v25=25, v26=26, v27=27, v30=30, v31=31, v32=32;
int v35=35, v36=36, v37=37, v40=40, v41=41, v42=42, v45=45, v46=46, v47=47;
cont.push_back(arr[v0]); cont.push_back(arr[v1]); cont.push_back(arr[v5]); cont.push_back(arr[v6]); cont.push_back(arr[v10]);
cont.push_back(arr[v11]); cont.push_back(arr[v15]); cont.push_back(arr[v16]); cont.push_back(arr[v20]); cont.push_back(arr[v21]);
cont.push_back(arr[v25]); cont.push_back(arr[v26]); cont.push_back(arr[v30]); cont.push_back(arr[v31]); cont.push_back(arr[v35]);
cont.push_back(arr[v36]); cont.push_back(arr[v40]); cont.push_back(arr[v41]); cont.push_back(arr[v45]); cont.push_back(arr[v46]);
cont2.push_back(arr[v2]); cont2.push_back(arr[v7]); cont2.push_back(arr[v12]); cont2.push_back(arr[v17]); cont2.push_back(arr[v22]);
cont2.push_back(arr[v27]); cont2.push_back(arr[v32]); cont2.push_back(arr[v37]); cont2.push_back(arr[v42]); cont2.push_back(arr[v47]);
std::vector<int>::iterator pt3 = cont2.begin();
std::vector<int>::iterator Ist_item = cont.begin();
std::vector<int>::iterator lst_item = cont.end();
for ( chk1 = Ist_item; chk1 != lst_item; chk1 ++)
{ for (chk2 = Ist_item ; chk2 != lst_item; chk2 ++)
{
if (chk2 != chk1 && *chk2 == *chk1)
{ //std::cout<<"there is a repeat and am gonna replace!";
add_value();
}
else
vll = *chk1;
cont3.push_back(vll);
// inserimento (testa, vll);
}
}
//print_on_screen(testa);
cont.empty();
cont2.empty();
}
void add_value()
{
int num = *pt3;
for (std::vector<int>::iterator pt = cont.begin(); pt != cont.end(); pt++)
{
if (num == * pt)
{
pt3++;
/*
y++;
if ( y >= cont2.size())
{
std::cout<<" we exceeded the replacing numbers, please insert number to use! waiting...";
int k;
std::cin>> k ;
cont3.push_back(k);
inserimento(testa, k); */
}
else
cont3.push_back(num);
// inserimento(testa, num);
}
}
void inserimento(Nodo * &testa, int numero)
{
Nodo *temp = new Nodo;
temp->valore = numero;
temp->nextPtr = 0;
if (testa==0) testa=temp;
else
{
Nodo *curr=testa;
while (curr->nextPtr!=0) curr=curr->nextPtr;
curr->nextPtr = temp;
}
}
void print_on_screen(std::vector<int>)
{
std::cout << std::endl << std::endl;
for(std::vector<int>::iterator ptr = cont3.begin(); ptr != cont3.end(); ptr ++)
std::cout << " , " << *ptr;// << std::endl;
}
void write_to_file (std::vector<int>)
{
std::fstream file;
file.open("organizeddddd.txt",std::ios::app);
if (file.is_open())
{ file<<"{";
for(std::vector<int>::iterator ptr = cont3.begin(); ptr != cont3.end(); ptr ++)
{
file << "," << *ptr ;
}
file<<"},"<<std::endl;
std::cout<<"writing to file was successful...";
}
else
std::cout<<"Could not open file, corrupt or does not exist in location...";
}
|