I just want to say “niubi”!!!
chenhao edited 3 年,8 月前
//----------------------------------------------------------------------
//
// Test.cpp : Test program for paperless.
//
//----------------------------------------------------------------------
using namespace std;
/*************/
//#include “paperless.h” // your header file for class paperless
class paperless
{
private:
map>> data; //Student’s submission
map submission; //Students’ amount of submission
public:
struct bad_paperless
{
int gg;
};
void submit(string Sid,int Snum,string Scode)
{
if(data.find(Sid)!=data.end()) //Student is in the map already
{
data[Sid][Snum].push(Scode);
submission[Sid]++;
//submission.insert(pair<string,int>(Sid,1));
}
else //Create a new student's data
{
pair<string,vector<stack<string>>> tem;
tem.first = Sid; //Student's ID
tem.second.resize(101); //Resize the vector
tem.second[Snum].push(Scode);
data.insert(tem);
}
}
void discard(string Sid,int Snum)
{
bad_paperless g;
g.gg = 1;
if(!data[Sid][Snum].empty()) data[Sid][Snum].pop();
else if(data[Sid][Snum].empty()) throw g;
}
int count(int Snum)
{
int s = 0;
for(auto tt:data)
{
if(!tt.second[Snum].empty()) s++;
}
return s;
}
};
/*************/
int main(int argc, char argv)
{
/**********/
paperless ams;
/************/
int assignNo; string id,code,skipEOL;
char c{};
do
{try
{ switch(c)
{
case 's': // submit
cout << "ID#: "; cin >> id;
cout << "Assign#: "; cin >> assignNo; getline(cin,skipEOL);
cout << "Code: "; getline(cin,code);
/**********/
ams.submit(id,assignNo,code);
/**********/
break;
case ‘d’: // discard
cout << “ID#: “; cin >> id;
cout << “Assign#: “; cin >> assignNo; getline(cin,skipEOL);
/**********/
ams.discard(id,assignNo);
/**********/
break;
case ‘c’: // count
cout << “Assign#: “; cin >> assignNo;
cout << “Total updated submissions of assignment #” << assignNo << ” : “
/**********/
<< ams.count(assignNo)
/**********/
<< endl;getline(cin,skipEOL);
break;
}
}
// * exception handling
/**********/
catch(paperless::bad_paperless g) // catch exceptions related to paperless
/*************/
{ cerr << “bad paperless operation! ” << endl; }
catch(…) // catch any exceptions
} while(cout<<endl<<"Enter a command('s','d','c','q'):"<<endl,cin.get(c),c!='q');
return 0;
}
帅