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
|
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
using namespace std;
struct ActiveCodes
{
string code;
bool flag;
};
void swap(ActiveCodes A[], int i, int j)
{
ActiveCodes temp;
temp=A[i];
A[i]=A[j];
A[j]=temp;
return;
}
void sort(ActiveCodes A[], int size)
{
for(int p=1; p<size; p++)
{
for(int c=0; c<size-p; c++)
{
if(A[c].code>A[c+1].code) swap(A, c, c+1);
}
}
return;
}
bool LLDDLL(string CheckCode)
{
if(CheckCode.length()!=6)
{return false;}
else if(isalpha(CheckCode.at(0)) && isalpha(CheckCode.at(1)) && isdigit(CheckCode.at(2))
&& isdigit(CheckCode.at(3)) && isalpha(CheckCode.at(4)) && isalpha(CheckCode.at(5)))
{return true;}
else
{return false;}
}
bool active(string CheckCode[], ActiveCodes A[], int size)
{
if(CheckCode[size]==A[size].code)
{
A[size].flag=false;
}
return true;
}
int main()
{
ifstream fin1, fin2, fin3;
ofstream fout1, fout2, fout3, fout4;
fin1.open("ActiveCodes1.txt");
ActiveCodes A[100];
int a=0;
while(fin1>>A[a].code) //while reading in data from ActiveCodes1.txt
{
A[a].flag=true;
a++;
}
sort(A, a);
fin2.open("CheckCodes.txt");
int idNum[100];
string CheckCode[100];
int b=0;
fout1.open("ValidActiveCodes.txt");
fout2.open("InactiveCodes.txt");
fout3.open("InvalidCodes.txt");
while(fin2>>idNum[b]>>CheckCode[b]) //while reading in data from CheckCodes.txt
{
if(LLDDLL(CheckCode[b])) //if valid
{
if(active(CheckCode, A, b)) //if active
{
fout1<<idNum[b]<<"\t"<<CheckCode[b]<<endl;
}
else
{
fout2<<idNum[b]<<"\t"<<CheckCode[b]<<endl;
}
}
else //if not valid
{
fout3<<idNum[b]<<"\t"<<CheckCode[b]<<endl;
}
b++;
}
fout4.open("ActiveCodes2.txt");
for(int c=0; c<b; c++)
{
if(A[c].flag = true)
{
fout4<<A[c].code<<endl;
c++;
}
}
fin1.close();
fin2.close();
fin3.close();
fout1.close();
fout2.close();
fout3.close();
fout4.close();
return 0;
}
|