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 |
谁有测试数据帮我看看是哪里的问题啊?#include<iostream> #include<string> #include<map> using namespace std; class value { public: string parent; int age; int visited; value(string s,int i) { visited = 0; parent = s; age = i; } }; map<string,value*> set; int Adjust(map<string,value*> m,string name) { value* temp = m[name]; if(m[name]->parent != "Ted") { int i = m[name]->age; return m[name]->age + Adjust(m,m[name]->parent); } else { if(m[name]->visited) { return 100 - m[name]->age; } else { return m[name]->age; } } } int main() { int count = 0; int sum = 0; string fname; string cname; int age = 0; cin>>count; while(count > 0) { cin>>sum; int i = 0; map<string, value*>::iterator it; for(;i<sum;i++) { cin>>fname; cin>>cname; cin>>age; value* v = new value(fname,age); set[cname] = v; } for(it = set.begin(); it != set.end(); ++it) { set[it->first]->age = 100 - Adjust(set,it->first); set[it->first]->visited = 1; }; cout<<"DATASET "<<sum<<endl; while(sum > 0) { int compare = -1; string output = ""; for(it = set.begin(); it != set.end(); ++it) { if(output == "") { compare = set[it->first]->age; output = it->first; } else if(compare < set[it->first]->age) { compare = set[it->first]->age; output = it->first; } }; set.erase(set.find(output)); cout<<output<<" "<<compare<<endl; sum--; } count--; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator