#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
void sort(struct card cards[]);
enum dotnum{three,four,five,six,seven,eight,nine,ten,J,Q,K,A,two,sking,bking};
enum dise{red,green,blue,white,pink,purple};
enum huase{hongxi,heitiao,fangkuai,meihua};
void creatno();
struct card
{
enum dotnum a;//代表点数
enum dise b;//代表底色
enum huase c;//代表花色
} cards[324],showcard;
void creatno()
{
int i;
for(i=0;i<324;i++)
{ cards[i].a=(enum dotnum)(rand()%15);
cards[i].b=(enum dise)(rand()%6);
cards[i].c=(enum huase)(rand()%4);
}
ofstream outfile1("before.txt");
if(!outfile1)
{cerr<<"can't open file."<<endl;
exit(1);
}
outfile1<<"dotnum"<<" ";
outfile1<<"dise"<<" ";
outfile1<<"huase"<<" "<<endl;
for(i=0;i<324;i++)
{
outfile1<<cards[i].a<<" ";
outfile1<<cards[i].b<<" ";
outfile1<<cards[i].c<<" ";
outfile1<<endl<<endl;
}
}
void sort(struct card cards[])
{
int i,j;
for(i=0;i<323;i++)
for(j=0;j<324;j++)
if(cards[i].a>cards[i+1].a)
{showcard=cards[i];cards[i]=cards[i+1];cards[i+1]=showcard;}
else {if(cards[i].b>cards[i+1].b)
{ showcard=cards[i];cards[i]=cards[i+1];cards[i+1]=showcard;}
else if(cards[i].c>cards[i+1].c)
{showcard=cards[i];cards[i]=cards[i+1];cards[i+1]=showcard;}
}
}
void arrayout(struct card cards[])
{
ofstream outfile2("after.txt");
if(!outfile2)
{
cerr<<"can't open file."<<endl;
exit(1);
}
outfile2<<"dotnum"<<" ";
outfile2<<"dise"<<" ";
outfile2<<"huase"<<" "<<endl;
for(int i=0;i<324;i++)
{ outfile2<<cards[i].a<<" ";
outfile2<<cards[i].b<<" ";
outfile2<<cards[i].c<<" ";
outfile2<<endl<<endl;
}
}
void main()
{
creatno();
sort(cards);
arrayout(cards);
}