#include <stdio.h>
#include <mem.h>
#include <stdlib.h>
#include <time.h>
//---------------------------------------------------------------------------
const int iTotalQuestions = 50;
const int iGetScore = 2;
const double dDelScore = 1.0/3.0;
const int iSelects = 2;
const int iOKQuestions = 15;
const int iTotalTest = 1000000;
const double dLimitRate = 1.0/3.0;
const double dGuestMax = (iGetScore*iOKQuestions)*(dLimitRate)/dDelScore/iGetScore;
//---------------------------------------------------------------------------
struct SQItem
{
int Ans;
int Quess;
int Done;
};
struct SRItem
{
int Score;
int Count;
};
//---------------------------------------------------------------------------
SQItem *g_iExam = NULL;
SRItem *g_iResult = NULL;
//---------------------------------------------------------------------------
int GetQuestionSize(void)
{
return (iTotalQuestions-iOKQuestions);
}
//---------------------------------------------------------------------------
int GetResultSize(void)
{
int Size = ((int)dGuestMax+iOKQuestions)*iGetScore -
(iOKQuestions*iGetScore-(int)(dGuestMax*dDelScore)*iGetScore) + 1;
return Size;
}
//---------------------------------------------------------------------------
void GetQuestion(void)
{
int QSize = GetQuestionSize();
g_iExam = new SQItem[QSize];
if(g_iExam)
{
for(int i = 0; i < QSize; i++)
{
g_iExam[i].Ans = rand()%(iSelects);
g_iExam[i].Quess = 0;
g_iExam[i].Done = 0;
}
}
}
//---------------------------------------------------------------------------
void DelQuestion(void)
{
if(g_iExam)
{
delete []g_iExam;
g_iExam = NULL;
}
}
//---------------------------------------------------------------------------
void InitResult(void)
{
int RSize = GetResultSize();
g_iResult = new SRItem[RSize];
for(int i = 0; i < RSize; i++)
{
g_iResult[i].Score = 0;
g_iResult[i].Count = 0;
}
}
//---------------------------------------------------------------------------
void DelResult(void)
{
if(g_iResult)
{
delete []g_iResult;
g_iResult = NULL;
}
}
//---------------------------------------------------------------------------
void SortResult(void)
{
int RSize = GetResultSize();
SRItem tmp;
for(int i = 0; i < RSize; i++)
{
for(int j = i; j < RSize; j++)
{
if(g_iResult[i].Count < g_iResult[j].Count)
{
memcpy(&tmp, &g_iResult[i], sizeof(SRItem));
memcpy(&g_iResult[i], &g_iResult[j], sizeof(SRItem));
memcpy(&g_iResult[j], &tmp, sizeof(SRItem));
}
}
}
}
//---------------------------------------------------------------------------
void CalResult(void)
{
int QSize = GetQuestionSize();
int OCount = 0;
int XCount = 0;
for(int i = 0; i < QSize; i++)
{
if(g_iExam[i].Done == 1)
{
if(g_iExam[i].Ans == g_iExam[i].Quess)
{
OCount++;
}
else
{
XCount++;
}
}
}
double Total = iGetScore*(iOKQuestions+OCount) -
iGetScore*dDelScore*(XCount);
int RSize = GetResultSize();
//Old Result
for(int i = 0; i < RSize; i++)
{
//Finded
if(g_iResult[i].Score == (int)Total)
{
g_iResult[i].Count++;
return;
}
}
//New Result
for(int i = 0; i < RSize; i++)
{
//New Item
if(g_iResult[i].Score == 0)
{
g_iResult[i].Score = (int)Total;
g_iResult[i].Count++;
return;
}
}
}
//---------------------------------------------------------------------------
void WriteResult(void)
{
FILE *f = fopen("Result.txt", "wb");
if(f)
{
SortResult();
int RSize = GetResultSize();
for(int i = 0; i < RSize; i++)
{
if(g_iResult[i].Count != 0)
{
fprintf(f, "%07d, %d\r\n", g_iResult[i].Count, g_iResult[i].Score);
printf("%07d, %d\r\n", g_iResult[i].Count, g_iResult[i].Score);
}
}
printf("\r\n\r\n");
fclose(f);
}
}
//---------------------------------------------------------------------------
void GuessExam(void)
{
while(1)
{
int QSize = GetQuestionSize();
int index = rand()%(QSize);
if(g_iExam[index].Done == 0)
{
g_iExam[index].Quess = rand()%(iSelects);
g_iExam[index].Done = 1;
break;
}
}
}
//---------------------------------------------------------------------------
int main(int argc, char *argv[])
{
srand((unsigned int)time(0));
InitResult();
for(int i = 0; i < iTotalTest; i++)
{
int count = 0;
GetQuestion();
while(1)
{
GuessExam();
count++;
if(count == (int)dGuestMax)
{
break;
}
}
CalResult();
DelQuestion();
}
WriteResult();
DelResult();
system("pause");
return 0;
}
//---------------------------------------------------------------------------
#include <mem.h>
#include <stdlib.h>
#include <time.h>
//---------------------------------------------------------------------------
const int iTotalQuestions = 50;
const int iGetScore = 2;
const double dDelScore = 1.0/3.0;
const int iSelects = 2;
const int iOKQuestions = 15;
const int iTotalTest = 1000000;
const double dLimitRate = 1.0/3.0;
const double dGuestMax = (iGetScore*iOKQuestions)*(dLimitRate)/dDelScore/iGetScore;
//---------------------------------------------------------------------------
struct SQItem
{
int Ans;
int Quess;
int Done;
};
struct SRItem
{
int Score;
int Count;
};
//---------------------------------------------------------------------------
SQItem *g_iExam = NULL;
SRItem *g_iResult = NULL;
//---------------------------------------------------------------------------
int GetQuestionSize(void)
{
return (iTotalQuestions-iOKQuestions);
}
//---------------------------------------------------------------------------
int GetResultSize(void)
{
int Size = ((int)dGuestMax+iOKQuestions)*iGetScore -
(iOKQuestions*iGetScore-(int)(dGuestMax*dDelScore)*iGetScore) + 1;
return Size;
}
//---------------------------------------------------------------------------
void GetQuestion(void)
{
int QSize = GetQuestionSize();
g_iExam = new SQItem[QSize];
if(g_iExam)
{
for(int i = 0; i < QSize; i++)
{
g_iExam[i].Ans = rand()%(iSelects);
g_iExam[i].Quess = 0;
g_iExam[i].Done = 0;
}
}
}
//---------------------------------------------------------------------------
void DelQuestion(void)
{
if(g_iExam)
{
delete []g_iExam;
g_iExam = NULL;
}
}
//---------------------------------------------------------------------------
void InitResult(void)
{
int RSize = GetResultSize();
g_iResult = new SRItem[RSize];
for(int i = 0; i < RSize; i++)
{
g_iResult[i].Score = 0;
g_iResult[i].Count = 0;
}
}
//---------------------------------------------------------------------------
void DelResult(void)
{
if(g_iResult)
{
delete []g_iResult;
g_iResult = NULL;
}
}
//---------------------------------------------------------------------------
void SortResult(void)
{
int RSize = GetResultSize();
SRItem tmp;
for(int i = 0; i < RSize; i++)
{
for(int j = i; j < RSize; j++)
{
if(g_iResult[i].Count < g_iResult[j].Count)
{
memcpy(&tmp, &g_iResult[i], sizeof(SRItem));
memcpy(&g_iResult[i], &g_iResult[j], sizeof(SRItem));
memcpy(&g_iResult[j], &tmp, sizeof(SRItem));
}
}
}
}
//---------------------------------------------------------------------------
void CalResult(void)
{
int QSize = GetQuestionSize();
int OCount = 0;
int XCount = 0;
for(int i = 0; i < QSize; i++)
{
if(g_iExam[i].Done == 1)
{
if(g_iExam[i].Ans == g_iExam[i].Quess)
{
OCount++;
}
else
{
XCount++;
}
}
}
double Total = iGetScore*(iOKQuestions+OCount) -
iGetScore*dDelScore*(XCount);
int RSize = GetResultSize();
//Old Result
for(int i = 0; i < RSize; i++)
{
//Finded
if(g_iResult[i].Score == (int)Total)
{
g_iResult[i].Count++;
return;
}
}
//New Result
for(int i = 0; i < RSize; i++)
{
//New Item
if(g_iResult[i].Score == 0)
{
g_iResult[i].Score = (int)Total;
g_iResult[i].Count++;
return;
}
}
}
//---------------------------------------------------------------------------
void WriteResult(void)
{
FILE *f = fopen("Result.txt", "wb");
if(f)
{
SortResult();
int RSize = GetResultSize();
for(int i = 0; i < RSize; i++)
{
if(g_iResult[i].Count != 0)
{
fprintf(f, "%07d, %d\r\n", g_iResult[i].Count, g_iResult[i].Score);
printf("%07d, %d\r\n", g_iResult[i].Count, g_iResult[i].Score);
}
}
printf("\r\n\r\n");
fclose(f);
}
}
//---------------------------------------------------------------------------
void GuessExam(void)
{
while(1)
{
int QSize = GetQuestionSize();
int index = rand()%(QSize);
if(g_iExam[index].Done == 0)
{
g_iExam[index].Quess = rand()%(iSelects);
g_iExam[index].Done = 1;
break;
}
}
}
//---------------------------------------------------------------------------
int main(int argc, char *argv[])
{
srand((unsigned int)time(0));
InitResult();
for(int i = 0; i < iTotalTest; i++)
{
int count = 0;
GetQuestion();
while(1)
{
GuessExam();
count++;
if(count == (int)dGuestMax)
{
break;
}
}
CalResult();
DelQuestion();
}
WriteResult();
DelResult();
system("pause");
return 0;
}
//---------------------------------------------------------------------------
沒有留言:
張貼留言