USACO Greedy gift
程序代码:
/* ID: liuyuan3 PROG: gift1 LANG: C++ */ #include <cstdlib> #include <iostream> #include <string> #include <fstream> #include <cassert> #define MAXP 10 using namespace std; class Person{ string name; int total; public: int get_total1(){return total;} string get_name1(){return name;} void set_name1(string nam){this->name=nam;} void set_total1(int t){this->total=t;} Person(string nam){name=nam;} Person(){} }; Person persons[MAXP]; int nop; void Addperson(string& nam){ assert(nam.size()<MAXP); persons[nop].set_name1(nam); nop++; } Person *lookup(string& nam) { for(int i=0;i<nop;i++) if(persons[nop].get_name1()==nam) return &persons[i]; assert(0); } int main(void){ string name; //void print(int); ofstream ouf("gift1.out"); ifstream inf("gift1.in"); if(inf.fail()){ cout<<"open error!"<<endl; system("PAUSE"); exit(1);} if(ouf.fail()){ cout<<"open error!"<<endl; system("PAUSE"); exit(1);} int i, j, np, amt, ng; Person *giver, *receiver; inf>>np; for(i=0;i<np;i++){ inf>>name; Addperson(name); } for(i=0;i<np;i++){ inf>>name>>amt>>ng; giver=lookup(name); for(j=0; j<ng; j++) { inf>>name; receiver = lookup(name); giver->set_total1(giver->get_total1()-amt/ng); receiver->set_total1(receiver->get_total1()+amt/ng); } } for(int i=0;i<np;i++) {ouf<<(persons[i].get_name1())<<endl <<persons[i].get_total1()<<endl; system("PAUSE"); return 0; } }为什么编译通过。结果不对??