| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
测试数据和随机函数测试方法对于一直WA无法找出问题的朋友,可以找一个AC的代码。然后将结果和自己程序的结果作比较。将不相等的输出通过写文件的形式写入文件中,然后比较分析。可能一个极小的点就一直无法过某组数据。通过长时间大量随机数据分析,可以找出出错的数据。
示例
#include <iostream>
#include <list>
#include <stack>
#include <string>
#include <queue>
#include <iomanip>
#include <time.h>
#include <fstream>
#define TESTBYCHENQK 0
#define USEAC 1
#if TESTBYCHENQK
#include <fstream>
#endif
using namespace std;
#if USEAC
bool tie;
int n,m,t,acI,a[100],b[100],x[100],used[100],tx[100],tmax[10];
int ans,ansnum,ansmax,ansrec[100];
int mmax,num,tnum,last;
list<string> lstAc;
list<string> lstMy;
string strAc;
string strMy;
char chMy[100];
char chAc[100];
bool same()
{
if (num!=ansnum) return false;
for (int iii=0;iii<num;iii++)
if (ansrec[iii]!=x[iii]) return false;
return true;
}
void dfs(int get,int kind)
{
if (get==b[acI])
{
if ((kind>ans)||((kind==ans) &&(ansnum>num))||((kind==ans)&&(ansnum==num)&&(mmax>ansmax)))
{
tie=false;
ans=kind;
ansnum=num;
ansmax=mmax;
for (int iii=0;iii<num;iii++) ansrec[iii]=x[iii];
return;
};
if ((kind==ans)&&(ansnum==num)&&(ansmax==mmax)&&(!same()))
{
tie=true;
return;
}
return;
}
if ((get>b[acI])||(num>=4)) return;
for (int ii=last;ii<n;ii++)
{
used[ii]++;
tmax[num]=mmax;
num++;
last=ii;
mmax=a[ii]>mmax?a[ii]:mmax;
x[num-1]=ii;
dfs(get+a[ii],kind+(used[ii]==1));
mmax=tmax[num];
num--;
used[ii]--;
}
}
void solve()
{
for (acI=0;acI<m;acI++)
{
for (int j=1;j<=4;j++) x[j]=0;
for (int j=0;j<m;j++) used[j]=0;
tie=false;
mmax=0;
num=0;
ans=0;
ansmax=0;
ansnum=10000;
last=0;
dfs(0,0);
#ifndef USEAC
if (!ans) {cout<<b[acI]<<" ---- none"<<endl; continue;}
cout<<b[acI]<<" ("<<ans<<")"<<": ";
if (tie) cout<<"tie"<<endl;
else
{
for (int ii=0;ii<ansnum-1;ii++) cout<<a[ansrec[ii]]<<" ";
cout<<a[ansrec[ansnum-1]]<<endl;
}
#endif
#if USEAC
strAc.clear();
if (!ans)
{
sprintf(chAc,"%d",b[acI]);
strAc += chAc;
strAc += " ---- none\n";
lstAc.push_back(strAc);
continue;
}
//cout<<b[acI]<<" ("<<ans<<")"<<": ";
sprintf(chAc,"%d",b[acI]);
strAc += chAc;
strAc += " (";
sprintf(chAc,"%d",ans);
strAc += chAc;
strAc += "): ";
if (tie)
{
strAc += "tie\n";
}
else
{
for (int ii=0;ii<ansnum-1;ii++)
{
//cout<<a[ansrec[ii]]<<" ";
sprintf(chAc,"%d ",a[ansrec[ii]]);
strAc += chAc;
}
sprintf(chAc,"%d",a[ansrec[ansnum-1]]);
strAc += chAc;
strAc += "\n";
//cout<<a[ansrec[ansnum-1]]<<endl;
}
lstAc.push_back(strAc);
#endif
}
}
#if 0
int main()
{
while (cin>>t)
{
n=1; a[0]=t; cin>>t;
while (t) {n++; a[n-1]=t; cin>>t;}
m=0; cin>>t;
while (t) {m++; b[m-1]=t; cin>>t;}
solve();
}
return 0;
}
#endif
#endif
struct Stamp
{
int nStampId;
int nStampValue;
};
struct Customer
{
int nCustomerId;
int nTotalValue;
};
struct StampCalculate
{
Stamp stampData;
int nCalValue;
int nIndex;
int nSame;
list<Stamp>::iterator lstStampIt;
};
struct ElementCalculate
{
int nValue;
int nCount;
//int nTypes;
};
int GetMaxOrMinStampValue(list<Stamp> paramListStamp,int nMaxOrMin)
{
list<Stamp>::iterator it;
int nMaxValue = paramListStamp.begin()->nStampValue;
for(it=paramListStamp.begin();it != paramListStamp.end();it++)
{
if(nMaxOrMin == 0)
{
if(nMaxValue< (*it).nStampValue )
{
nMaxValue = (*it).nStampValue;
}
}
else
{
if(nMaxValue> (*it).nStampValue )
{
nMaxValue = (*it).nStampValue;
}
}
}
return nMaxValue;
}
void SortListStamp(list<Stamp>& paramListStamp,int nSortBy)
{
list<Stamp>::iterator it;
list<Stamp>::iterator it2;
list<Stamp>::iterator it3;
list<Stamp>::iterator itPrevEnd;
int nTempValue;
int nTempId;
bool bCompare = false;
itPrevEnd = paramListStamp.end();
itPrevEnd--;
for(it=paramListStamp.begin();it != itPrevEnd; it++)
{
for(it2 = itPrevEnd;it2 != it;it2--)
{
it3 = it2;
it3--;
if(nSortBy == 0)
{
bCompare = (*it3).nStampValue > (*it2).nStampValue;
}
else if(nSortBy == 1)
{
bCompare = (*it3).nStampId > (*it2).nStampId ;
}
if(bCompare)
{
nTempValue = (*it3).nStampValue;
nTempId = (*it3).nStampId;
(*it3).nStampId = (*it2).nStampId;
(*it3).nStampValue = (*it2).nStampValue;
(*it2).nStampId = nTempId;
(*it2).nStampValue = nTempValue;
}
}
}
}
bool IsInStack(stack<StampCalculate> stackStamp,int nStampId)
{
if(stackStamp.empty())
{
return false;
}
else
{
while(!stackStamp.empty())
{
if(stackStamp.top().stampData.nStampId == nStampId)
{
return true;
}
else
{
stackStamp.pop();
}
}
}
return false;
}
int GetStackMaxStampValue(stack<StampCalculate> stackStamp)
{
int nMaxStampValue = 0;
if(stackStamp.empty())
{
return 0;
}
else
{
while(!stackStamp.empty())
{
if(stackStamp.top().stampData.nStampValue> nMaxStampValue)
{
nMaxStampValue = stackStamp.top().stampData.nStampValue;
}
stackStamp.pop();
}
}
return nMaxStampValue;
}
int GetStackTypes(stack<StampCalculate> stackStamp)
{
int nTypes = 0;
list<int> lstIntIndex;
list<int>::iterator it;
StampCalculate stampCal;
while(!stackStamp.empty())
{
stampCal = stackStamp.top();
if(lstIntIndex.empty())
{
nTypes = 1;
lstIntIndex.push_back(stampCal.stampData.nStampId);
}
else
{
for(it = lstIntIndex.begin();it != lstIntIndex.end();it++)
{
if((*it) == stampCal.stampData.nStampId)
{
break;
}
}
if(it == lstIntIndex.end())
{
nTypes ++;
}
lstIntIndex.push_back(stampCal.stampData.nStampId);
}
stackStamp.pop();
}
return nTypes;
}
void SortQueueByLengthAndMaxValue(queue<stack<StampCalculate> > &queStoreStack)
{
stack<StampCalculate> stackStamp;
stack<StampCalculate> stackStamp2;
stack<StampCalculate> stackStampTemp;
list<stack<StampCalculate> > lstStoreStackBackup;
list<stack<StampCalculate> >::iterator itBackup;
list<stack<StampCalculate> >::iterator itBackup2;
list<stack<StampCalculate> >::iterator itBackup3;
list<stack<StampCalculate> >::iterator itLast;
int nByTypes = 0;
int nByTypes2 = 0;
int nMaxStampValue = 0;
int nMaxStampValue2 = 0;
//int nGetStackValue = 0;
//stack<StampCalculate> stackStampMax;
while(!queStoreStack.empty())
{
stackStamp=queStoreStack.front();
queStoreStack.pop();
lstStoreStackBackup.push_back(stackStamp);
}
itLast = lstStoreStackBackup.end();
if(!lstStoreStackBackup.empty())
itLast--;
for(itBackup = lstStoreStackBackup.begin();itBackup != itLast;itBackup++)
{
for(itBackup2 = itLast;itBackup2 != itBackup;itBackup2--)
{
itBackup3 = itBackup2;
itBackup3 --;
stackStamp = (*itBackup2);
stackStamp2 = (*itBackup3);
nByTypes = GetStackTypes(stackStamp);
nByTypes2 = GetStackTypes(stackStamp2);
if(nByTypes > nByTypes2)
{
(*itBackup2) = stackStamp2;
(*itBackup3) = stackStamp;
}
else if(nByTypes == nByTypes2)
{
if(stackStamp.size() < stackStamp2.size())
{
(*itBackup2) = stackStamp2;
(*itBackup3) = stackStamp;
}
else if(stackStamp.size() == stackStamp2.size())
{
nMaxStampValue = GetStackMaxStampValue(stackStamp);
nMaxStampValue2 = GetStackMaxStampValue(stackStamp2);
if(nMaxStampValue > nMaxStampValue2)
{
(*itBackup2) = stackStamp2;
(*itBackup3) = stackStamp;
}
else if(nMaxStampValue == nMaxStampValue2)
{
if(stackStamp.top().nCalValue > stackStamp2.top().nCalValue)
{
(*itBackup2) = stackStamp2;
(*itBackup3) = stackStamp;
}
}
}
}
}
}
for(itBackup = lstStoreStackBackup.begin();itBackup != lstStoreStackBackup.end();itBackup++)
{
stackStamp = (*itBackup);
queStoreStack.push(stackStamp);
}
//stackStamp=queStoreStack.front();
}
bool IsStackStampTie(stack<StampCalculate> stackStamp,list<Stamp> paramListStamp)
{
list<Stamp>::iterator it;
list<ElementCalculate> lstEleCal;
list<ElementCalculate>::iterator itEleCal;
StampCalculate stampCal;
ElementCalculate eleCal;
int nCountInList = 0;
bool bFindElement = 0;
while(!stackStamp.empty())
{
stampCal = stackStamp.top();
if(lstEleCal.empty())
{
eleCal.nValue = stampCal.stampData.nStampValue;
eleCal.nCount = 1;
lstEleCal.push_back(eleCal);
}
else
{
for(itEleCal = lstEleCal.begin(); itEleCal != lstEleCal.end();itEleCal++)
{
if((*itEleCal).nValue == stampCal.stampData.nStampValue)
{
(*itEleCal).nCount ++;
break;
}
}
if(itEleCal == lstEleCal.end())
{
eleCal.nValue = stampCal.stampData.nStampValue;
eleCal.nCount = 1;
lstEleCal.push_back(eleCal);
}
}
stackStamp.pop();
}
for(itEleCal = lstEleCal.begin();itEleCal != lstEleCal.end(); itEleCal++)
{
bFindElement = false;
nCountInList = 0;
for(it = paramListStamp.begin(); it != paramListStamp.end();it++)
{
if(!bFindElement)
{
if((*it).nStampValue == (*itEleCal).nValue)
{
bFindElement = true;
nCountInList = 1;
}
}
else
{
if((*it).nStampValue == (*itEleCal).nValue)
{
nCountInList ++;
}
else
{
break;
}
}
}
if((*itEleCal).nCount != nCountInList && nCountInList > 1)
{
return true;
}
}
return false;
}
bool IsSameStack(stack<StampCalculate>stackCompare,stack<StampCalculate> stackCal)
{
if(stackCompare.size() != stackCal.size())
return false;
else
{
while(!stackCompare.empty() && !stackCal.empty())
{
if(stackCompare.top().stampData.nStampId!= stackCal.top().stampData.nStampId)
return false;
stackCompare.pop();
stackCal.pop();
}
}
return true;
}
bool GetBetterStack(stack<StampCalculate>& stackBetter,stack<StampCalculate> stackCal)
{
int nStackBetterTypes = 0;
int nStackCalTypes = 0;
int nMaxStackBetterValue = 0;
int nMaxStackValue = 0;
nStackBetterTypes = GetStackTypes(stackBetter);
nStackCalTypes = GetStackTypes(stackCal);
nMaxStackBetterValue = GetStackMaxStampValue(stackBetter);
nMaxStackValue = GetStackMaxStampValue(stackCal);
if(nStackCalTypes > nStackBetterTypes)
{
stackBetter = stackCal;
stackBetter.top().nSame = 1;
return true;
}
else if(nStackCalTypes == nStackBetterTypes)
{
if(stackBetter.size() > stackCal.size())
{
stackBetter = stackCal;
stackBetter.top().nSame = 1;
return true;
}
else if(nMaxStackBetterValue < nMaxStackValue)
{
stackBetter = stackCal;
stackBetter.top().nSame = 1;
return true;
}
else if(stackBetter.size() == stackCal.size() && nMaxStackBetterValue == nMaxStackValue)
{
stackBetter.top().nSame++;
}
}
return false;
}
bool GetBoolPushStack(stack<StampCalculate> stackStamp,int nStampValue,bool bLastIterator,int nCustomerRequest,int nBack,int nBackTimes,int nStampId)
{
bool bLtTotalValue;
if (bLastIterator)
{
bLtTotalValue = false;
}
else
{
if(nBack == 0)
{
if(stackStamp.empty() && nStampValue <= nCustomerRequest)
{
bLtTotalValue = true;
}
else if(!stackStamp.empty() && stackStamp.size() < 3 && nStampValue+ stackStamp.top().nCalValue <= nCustomerRequest)
{
bLtTotalValue = true;
}
else if((stackStamp.size() == 3) && nStampValue + stackStamp.top().nCalValue == nCustomerRequest)
{
bLtTotalValue = true;
}
else
{
bLtTotalValue = false;
}
}
else
{
if(IsInStack(stackStamp,nStampId))
{
if(nBackTimes % 2 == 0)
{
if(nStampValue + stackStamp.top().nCalValue == nCustomerRequest)
{
bLtTotalValue = true;
}
else
{
bLtTotalValue = false;
}
}
else
{
if(!stackStamp.empty() && stackStamp.size() < 3 && nStampValue+ stackStamp.top().nCalValue <= nCustomerRequest)
{
bLtTotalValue = true;
}
else if((stackStamp.size() == 3) && nStampValue + stackStamp.top().nCalValue == nCustomerRequest)
{
bLtTotalValue = true;
}
else
{
bLtTotalValue = false;
}
}
}
else
{
bLtTotalValue = false;
}
}
}
return bLtTotalValue;
}
void CalculateResult(list<Stamp>& lstResultStamp,int& nTypesInList,stack<StampCalculate> stackStampBest,list<Stamp> paramListStamp)
{
bool bIsTie = false;
int nIsTie = 0;
Stamp stampResult;
if(lstResultStamp.size()!=0)
lstResultStamp.clear();
bIsTie = IsStackStampTie(stackStampBest,paramListStamp);
if(bIsTie)
{
stackStampBest.top().nSame ++;
}
if(!stackStampBest.empty()&&stackStampBest.top().nSame > 1)
{
nIsTie = 1;
}
else
{
nIsTie = 0;
}
while(!stackStampBest.empty())
{
stampResult= stackStampBest.top().stampData;
if(lstResultStamp.size() > 0)
{
list<Stamp>::iterator it;
for(it = lstResultStamp.begin();it != lstResultStamp.end();it++)
{
if((*it).nStampId == stampResult.nStampId)
{
break;
}
}
if(it == lstResultStamp.end())
{
it -- ;
nTypesInList++;
}
lstResultStamp.insert(it,stampResult);
}
else
{
lstResultStamp.push_back(stampResult);
nTypesInList++;
}
stackStampBest.pop();
}
if(lstResultStamp.size() != 0)
{
SortListStamp(lstResultStamp,1);
if(nIsTie == 1)
{
lstResultStamp.begin()->nStampId = -1;
}
}
}
bool PushQueue(queue<stack<StampCalculate> > & queStoreStack,int& nMaxTypes,stack<StampCalculate> stackStamp,bool bEqualRequest,bool bOrder)
{
int nNowTypes = GetStackTypes(stackStamp);
stack<StampCalculate> stackStampTemp;
bool bEntrance = false;
if(bEqualRequest)
{
if(nMaxTypes <= nNowTypes)
bEntrance = true;
}
else
{
if(nMaxTypes <= nNowTypes || nNowTypes >= 1)
bEntrance = true;
}
if(bEntrance)
{
if(nMaxTypes < nNowTypes && bEqualRequest)
nMaxTypes = nNowTypes;
if(stackStamp.size()<4)
{
if(queStoreStack.empty())
{
queStoreStack.push(stackStamp);
}
else
{
stackStampTemp = queStoreStack.back();
if(!IsSameStack(stackStampTemp,stackStamp))
{
queStoreStack.push(stackStamp);
}
}
}
}
else
{
if(bOrder&&bEqualRequest)
return true;
}
return false;
}
void GetAllocateStampList(list<Stamp> paramListStamp,int nCustomerRequest,list<Stamp> & lstResultStamp,int& nTypesInList)
{
list<Stamp>::iterator itStamp;
stack<StampCalculate> stackStamp;
stack<StampCalculate> stackStampBest;
stack<StampCalculate> stackStampTemp;
queue<stack<StampCalculate> > queStoreStack;
list<Stamp>::iterator itTemp;
StampCalculate stampCal;
bool bLtTotalValue;
int nTimesToListEnd = 0;
int i = 0;
int nNeedBegin = -1;
int nBack = 0;
bool bNewBetter = false;
int nStampValue = 0;
int nStampId = 0;
bool bLastIterator = 0;
int nMaxTypes = 0;
int nNowTypes = 0;
bool bFindBest = false;
bool bOrder = true;
bool bMustBack = true;
int nTolreance = 0;
int nBackOposite = 0;
list<stack<StampCalculate> > lstStackStamp;
nTypesInList = 0;
SortListStamp(paramListStamp,0);
while(!stackStamp.empty())
{
stackStamp.pop();
}
if(nCustomerRequest > 2*GetMaxOrMinStampValue(paramListStamp,0))
{
bOrder = false;
paramListStamp.reverse();
}
itStamp = paramListStamp.begin();
do
{
nStampValue = (itStamp != paramListStamp.end()?(*itStamp).nStampValue:0);
nStampId = (itStamp != paramListStamp.end()?(*itStamp).nStampId:0);
bLastIterator = (itStamp == paramListStamp.end());
if(!bOrder) nBack = nBackOposite;
bLtTotalValue = GetBoolPushStack(stackStamp,nStampValue,bLastIterator,nCustomerRequest,nBack,nNeedBegin,nStampId);
if(bOrder&& nBack == 1 && nNeedBegin == -1)
bLtTotalValue = false;
if(bLtTotalValue)
{
stampCal.nIndex = stackStamp.size()+1;
stampCal.stampData.nStampId = (*itStamp).nStampId;
stampCal.stampData.nStampValue = (*itStamp).nStampValue;
stampCal.lstStampIt = itStamp;
if(!stackStamp.empty())
{
stampCal.nCalValue = stackStamp.top().nCalValue + stampCal.stampData.nStampValue;
}
else
{
stampCal.nCalValue = stampCal.stampData.nStampValue;
}
stackStamp.push(stampCal);
}
if(itStamp != paramListStamp.end())
itStamp ++;
if(!stackStamp.empty()&&stackStamp.top().nCalValue == nCustomerRequest)
{
if(!bFindBest) bFindBest = true;
bNewBetter = GetBetterStack(stackStampBest,stackStamp);
if(stackStampBest.top().nSame > 1 && stackStampBest.size() == 4)
break;
if(!bOrder) nBack = 0;
if(!nBack)
{
if(PushQueue(queStoreStack,nMaxTypes,stackStamp,true,bOrder))
break;
stampCal = stackStamp.top();
if(stackStamp.size() > 3)
{
stackStamp.pop();
stackStamp.pop();
}
else if(stackStamp.size() >= 2)
{
stackStamp.pop();
}
itStamp = stackStamp.top().lstStampIt;
itStamp++;
stackStamp.pop();
#if 0
if(bFindBest&&bOrder)
{
if(!stackStamp.empty())
{
stampCal.nCalValue = stackStamp.top().nCalValue + stampCal.stampData.nStampValue;
stackStamp.push(stampCal);
}
else if(nCustomerRequest != stampCal.stampData.nStampValue)
{
stampCal.nCalValue = stampCal.stampData.nStampValue;
stackStamp.push(stampCal);
}
}
#endif
if(!bOrder)
{
bMustBack = true;
nTolreance = 0;
}
}
else if(bOrder)
{
if(!queStoreStack.empty())
{
stackStamp = queStoreStack.front();
queStoreStack.pop();
}
else
{
break;
}
nNeedBegin = 0;
itStamp = paramListStamp.begin();
}
}
else if(itStamp == paramListStamp.end())
{
if(!bOrder) nBack = 0;
if(!nBack)
{
if(!stackStamp.empty())
{
itStamp = stackStamp.top().lstStampIt;
while(itStamp != paramListStamp.end())
{
itStamp++;
if(itStamp != paramListStamp.end() && (*itStamp).nStampValue != stackStamp.top().stampData.nStampValue)
{
break;
}
}
if(!bFindBest && bOrder)
{
PushQueue(queStoreStack,nMaxTypes,stackStamp,false,bOrder);
}
if(bOrder)
stackStamp.pop();
else
{
if(bMustBack)
{
itStamp = paramListStamp.begin();
if(nNeedBegin < 6)
{
if(nNeedBegin == -1)
{
stackStampTemp = stackStamp;
}
nNeedBegin ++;
nBackOposite = 1;
}
else
{
nTolreance++;
bMustBack = false;
nNeedBegin = 0;
itStamp = paramListStamp.end();
stackStamp = stackStampTemp;
//nBackOposite = 0;
}
}
else
{
bMustBack = true;
nNeedBegin = -1;
nBackOposite = 0;
if(nTolreance == 1)
{
stackStamp.pop();
nTolreance = 0;
}
}
}
}
if(stackStamp.empty() && itStamp == paramListStamp.end())
{
if(bOrder)
{
nBack = 1;
paramListStamp.reverse();
SortQueueByLengthAndMaxValue(queStoreStack);
}
else
{
break;
}
}
}
if(nBack == 1 && bOrder)
{
if(bFindBest) break;
if(!queStoreStack.empty())
{
if(nNeedBegin == -1)
{
stackStamp = queStoreStack.front();
queStoreStack.pop();
nNeedBegin ++;
}
else if(nNeedBegin < 6)
{
nNeedBegin ++;
}
else
{
nNeedBegin = -1;
}
itStamp = paramListStamp.begin();
}
else
{
break;
}
}
}
}while(!stackStamp.empty()||itStamp != paramListStamp.end());
CalculateResult(lstResultStamp,nTypesInList,stackStampBest,paramListStamp);
}
int AllocateStamp(list<Stamp> paramListStamp,list<Customer> paramListCustomer)
{
list<Stamp>::iterator itStamp;
stack<StampCalculate> stackStamp;
list<Customer>::iterator itCustomer;
list<Stamp> lstResult;
list<Stamp>::iterator itResult;
int nMaxValue = 0;
int nMinValue = 0;
int nTotal = 0;
int nTypes = 0;
for(itCustomer=paramListCustomer.begin();itCustomer != paramListCustomer.end();itCustomer++)
{
strMy.clear();
nMaxValue = GetMaxOrMinStampValue(paramListStamp,0);
nMinValue = GetMaxOrMinStampValue(paramListStamp,1);
if(nMaxValue*4 < (*itCustomer).nTotalValue||nMinValue > (*itCustomer).nTotalValue)
{
//cout <<(*itCustomer).nTotalValue <<" "<<"----"<<" none"<<endl;
sprintf(chMy,"%d",(*itCustomer).nTotalValue);
strMy += chMy;
strMy +=" ---- none\n";
}
else
{
GetAllocateStampList(paramListStamp,(*itCustomer).nTotalValue,lstResult,nTypes);
if(lstResult.size() == 0)
{
//cout <<(*itCustomer).nTotalValue <<" "<<"----"<<" none"<<endl;
sprintf(chMy,"%d",(*itCustomer).nTotalValue);
strMy += chMy;
strMy +=" ---- none\n";
}
else
{
if(lstResult.begin()->nStampId == -1)
{
//cout<<(*itCustomer).nTotalValue<<" "<<"("<<nTypes<<")"<<":"<<" tie"<<endl;
sprintf(chMy,"%d",(*itCustomer).nTotalValue);
strMy += chMy;
strMy += " (";
sprintf(chMy,"%d",nTypes);
strMy += chMy;
strMy +="): tie\n";
}
else
{
//cout<<(*itCustomer).nTotalValue<<" "<<"("<<nTypes<<")"<<":";
//for(itResult = lstResult.begin();itResult != lstResult.end();itResult++)
//{
//cout<<" "<<(*itResult).nStampValue;
//}
//cout<<endl;
sprintf(chMy,"%d",(*itCustomer).nTotalValue);
strMy += chMy;
strMy += " (";
sprintf(chMy,"%d",nTypes);
strMy += chMy;
strMy += "):";
for(itResult = lstResult.begin();itResult != lstResult.end();itResult++)
{
sprintf(chMy," %d",(*itResult).nStampValue);
strMy += chMy;
}
strMy += "\n";
}
}
}
cout << strMy;
lstMy.push_back(strMy);
}
return 0;
}
int main(int argc,char* argv[])
{
int nStamp;
int nCustomer;
list<Stamp> lstStamp;
list<Customer> lstCustomer;
list<Stamp>::iterator itStamp;
list<Customer>::iterator itCustomer;
Stamp stampTemp;
Customer customerTemp;
bool bEndStamp = false;
bool bEndCustomer = false;
int nStampNo = 0;
int nCustomerNo = 0;
int nIndexStamp = 0;
int nIndexCustomer = 0;
#if TESTBYCHENQK
fstream fs;
fs.open("F:\\test.txt",ios::in);
#endif
fstream fsdf;
fsdf.open("F:\\difference.txt",ios::app);
while(1)
{
lstStamp.clear();
lstCustomer.clear();
#if USEAC
n = 0;
m = 0;
srand( (unsigned)time( NULL ) );
nStampNo = (rand() % 100);
srand( (unsigned)time( NULL ) );
nCustomerNo = (rand() % 100);
#endif
#if 0
while(1)
{
#if TESTBYCHENQK
bEndStamp=(fs>>nStamp);
#else
bEndStamp=(cin>>nStamp);
#endif
if(nStamp == 0) break;
else
{
stampTemp.nStampId = lstStamp.size()+1;
stampTemp.nStampValue = nStamp;
lstStamp.push_back(stampTemp);
a[n++] = nStamp;
}
}
while(1)
{
#if TESTBYCHENQK
bEndCustomer=(fs>>nCustomer);
#else
bEndCustomer=(cin>>nCustomer);
#endif
if(nCustomer == 0)
break;
else
{
customerTemp.nCustomerId = lstCustomer.size()+1;
customerTemp.nTotalValue = nCustomer;
lstCustomer.push_back(customerTemp);
b[m++] = nCustomer;
}
}
#endif
#if 0
for(nIndexStamp = 0,n=0; nIndexStamp < nStampNo;nIndexStamp++)
{
do
{
nStamp = rand() % 100;
}while(nStamp == 0);
stampTemp.nStampId = lstStamp.size()+1;
stampTemp.nStampValue = nStamp;
lstStamp.push_back(stampTemp);
a[n++] = nStamp;
}
for(nIndexCustomer = 0,m = 0;nIndexCustomer < nCustomerNo;nIndexCustomer++)
{
do
{
nCustomer = rand() % 100;
}while(nCustomer == 0);
customerTemp.nCustomerId = lstCustomer.size()+1;
customerTemp.nTotalValue = nCustomer;
lstCustomer.push_back(customerTemp);
b[m++] = nCustomer;
}
#endif
#if 1
lstAc.clear();
lstMy.clear();
strAc.clear();
strMy.clear();
list<string>::iterator itAc;
list<string>::iterator itMy;
#endif
AllocateStamp(lstStamp,lstCustomer);
//solve();
#if 1
for(itAc = lstAc.begin(),itMy = lstMy.begin();itAc!=lstAc.end()&&itMy != lstMy.end();itAc++,itMy++)
{
if((*itAc) != (*itMy))
{
fsdf<<"stamp: "<<endl;
for(itStamp = lstStamp.begin();itStamp != lstStamp.end();itStamp++)
{
fsdf<<(*itStamp).nStampValue<<" ";
//cout<<(*itStamp).nStampValue<<" ";
}
fsdf <<endl;
//cout <<endl;
fsdf<<"customer: "<<endl;
for(itCustomer = lstCustomer.begin();itCustomer != lstCustomer.end();itCustomer++)
{
fsdf<<(*itCustomer).nTotalValue<<" ";
//cout<<(*itCustomer).nTotalValue<<" ";
}
fsdf <<endl;
//cout <<endl;
fsdf<<"difference customer request: "<<"AC "<<(*itAc)<<"MY "<<(*itMy)<<endl;
cout<<"difference customer request: "<<"AC "<<(*itAc)<<"MY "<<(*itMy)<<endl;
}
}
#endif
if(!bEndStamp&&!bEndCustomer)
break;
}
#if TESTBYCHENQK
system("pause");
#endif
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator