C++版 纳税题(通过率100%) #include #include using namespace std; int main(int argc, char* argv[]) { int T = 0; while(cin >> T) { for(int i=0;i<T;i++) { int N = 0; cin >> N; vector a = {0, 3000, 12000, 25000, 35000, 55000, 80000}; vector b = {0.03, 0.1, 0.2, 0.25, 0.3, 0.35, 0.45}; float sum = 0; int rest = N-5000; for(int i=0;i<b.size()-1;i++) { if(rest>a[i]) { sum += (rest>a[i+1]?(a[i+1]-a[i]):(rest-a[i])) * b[i]; } } if(rest>a[6]) { sum += (rest-a[6]) * b[6]; } sum += 0.5; cout << int(sum) << endl; } } return 0; 聊天会话列表题(通过率100%) #include <iostream> #include <string> #include <map> #include <vector> #include <algorithm> using namespace std; typedef struct Node { int id; string name; }Node; typedef struct compare { map<string, int> record; compare(map<string, int> record) { this->record = record; } bool operator () (Node a, Node b) { /* 状态不同 */ if(this->record[a.name]!=this->record[b.name]) { return this->record[a.name] > this->record[b.name]; } /* 身份不同 */ if(a.id!=b.id) { return a.id > b.id; } return a.name < b.name; } }compare; int main(int argc, char* argv[]) { int N = 0; while(cin >> N) { vector<Node> group; for(int i=0;i<N;i++) { int id = 0; string name; cin >> id >> name; group.push_back({id, name}); } int M = 0; cin >> M; map<string, int> record; for(int i=0;i<M;i++) { string name; int state; cin >> name >> state; record[name] = state; } compare cmp(record); stable_sort(group.begin(), group.end(), cmp); for(auto it:group) { cout << it.name << endl; } } return 0; } 时间区间题(通过率0%, 时间来不及,差一点了) #include <iostream> #include <vector> #include <map> using namespace std; typedef struct Node { int start; int end; }Node; int calc_time(map<int, vector<Node>>& schedule, int W, int& time, bool& flag) { int wait = 0; if(schedule.count(W)!=0) { for(auto it:schedule[W]) { if(time<it.start) { wait = it.start - time; flag = true; break; } if(time>=it.start && time<=it.end) { wait = 0; flag = true; break; } } if(!flag) { wait = 24 * 3600 - time; time = 0; } } else { wait = 24 * 3600 - time; time = 0; } return wait; } int main(int argc, char* argv[]) { int T = 0; while(cin >> T) { for(int i=0;i<T;i++) { int K = 0; cin >> K; map<int, vector<Node>> schedule; for(int j=0;j<K;j++) { int W = 0, M = 0; cin >> W >> M; for(int k=0;k<M;k++) { int HH, MM, SS; char ch; int start = 0, end = 0; cin >> HH >> ch >> MM >> ch >> SS; start = HH * 3600 + MM * 60 + SS; cin >> ch >> HH >> ch >> MM >> ch >> SS; end = HH * 3600 + MM * 60 + SS; schedule[W].push_back({start, end}); } } int C = 0; cin >> C; for(int j=0;j<C;j++) { int W = 0; int HH, MM, SS; char ch; cin >> W >> HH >> ch >> MM >> ch >> SS; int time = HH * 3600 + MM * 60 + SS; bool flag = false; int wait = calc_time(schedule, W, time, flag); while(!flag) { W++; wait += calc_time(schedule, W, time, flag); } cout << wait << endl; } } } return 0; }
点赞 评论

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务