ThoughtWorks 2018校园招聘作业题目 -- 出租车
2017-10-16 15:37
381 查看
题目描述
题目仅供技术交流,未经公司允许,不得传播。题目分析
这道题本身不难,按照保养规则模拟即可。但是,对于测试用例二的CAR0001,和CAR0003,根据题目中报废规则,笔者认为属于“报废”。但给出的输出没有包含这两辆车。
如下图所示:
参考代码
#include <bits/stdc++.h> using namespace std; int submitYear, submitMonth, submitDay; unordered_map<string, vector<string>> umap; void splitString(const std::string& s, std::vector<std::string>& v, const std::string& c) { std::string::size_type pos1, pos2; pos2 = s.find(c); pos1 = 0; while(std::string::npos != pos2) { v.push_back(s.substr(pos1, pos2-pos1)); pos1 = pos2 + c.size(); pos2 = s.find(c, pos1); } if(pos1 != s.length()) v.push_back(s.substr(pos1)); } vector<int> getDate(string str, vector<string>& vstring) { vector<int> res; splitString(str, vstring, "/"); res.push_back(stoi(vstring[0])); res.push_back(stoi(vstring[1])); res.push_back(stoi(vstring[2])); return res; } void carsMaintain(string str) { string carNumber; int produceYear, produceMonth, produceDay; int ageYear, ageMonth, ageDay; string company; int milesLength; bool isFixed = false; vector<string> vecString; vector<string> vecProduceDate; splitString(str, vecString, "|"); splitString(vecString[1], vecProduceDate, "/"); carNumber = vecString[0]; produceYear = stoi(vecProduceDate[0]); produceMonth = stoi(vecProduceDate[1]); produceDay = stoi(vecProduceDate[2]); ageYear = submitYear - produceYear; ageMonth = submitMonth - produceMonth; // Becareful the minus number ageDay = submitDay - produceDay; company = vecString[2]; milesLength = stoi(vecString[3]); isFixed = vecString[4] == "T"; // write off if (ageYear >= 6 || (ageYear >= 3 && isFixed)) { if (ageMonth <= 1) { umap["Write-Off"].push_back(str); } } // Distance related else if ((10000 - milesLength % 10000 <= 500) || milesLength %10000 == 0) { umap["Distance-Related"].push_back(str); } // Time related else { // has been fixed if (isFixed) { if (ageYear >= 1) { if ((12 - produceMonth + submitMonth) % 3 != 1) { umap["Time-Related"].push_back(str); } } else { if (ageMonth % 3 != 1) { umap["Time-Related"].push_back(str); } } } else if (ageYear >= 3) { if ((12 - produceMonth + submitMonth) % 6 == 0 || (12 - produceMonth + submitMonth) % 6 == 5) { umap["Time-Related"].push_back(str); } } else { if ((12 - produceMonth + submitMonth) % 12 == 0 || (12 - produceMonth + submitMonth) % 12 == 11) { umap["Time-Related"].push_back(str); } } } } map<string, vector<string>> printHelper(vector<string>& vecString) { map<string, vector<string>> mmap; for (auto str : vecString) { vector<string> vstr; splitString(str, vstr, "|"); mmap[vstr[2]].push_back(vstr[0]); } return mmap; } void printFormat(vector<string> vstr) { auto mmap = printHelper(vstr); for (auto item : mmap) { cout << item.first << ": " << item.second.size() << " "; for (int i = 0; i < item.second.size(); ++i) { if (i == 0) { if (i == item.second.size() - 1) cout << "(" << item.second[i] << ")"; else cout << "(" << item.second[i] << ","; } else if (i == item.second.size() - 1 ) cout << " " << item.second[i] << ")"; else cout << " " << item.second[i] << ","; } cout << endl; } } void printOut() { cout << "Reminder" << endl; cout << "==================" << endl; cout << endl; cout << "* Time-related maintenance coming soon..." << endl; printFormat(umap["Time-Related"]); cout << endl << "* Distance-related maintenance coming soon..." << endl; printFormat(umap["Distance-Related"]); cout << endl << "* Write-off coming soon..." << endl; printFormat(umap["Write-Off"]); } int main() { freopen("C:\\Users\\Administrator\\Desktop\\ClionTest\\taxi.in", "r", stdin); freopen("C:\\Users\\Administrator\\Desktop\\ClionTest\\taxi.out", "w", stdout); // get submit date from the first line string firstLine, submitDate; vector<string> vstring; getline(cin, firstLine); submitDate = firstLine.substr(firstLine.find(' ') + 1); vector<int> submitDateVec = getDate(submitDate, vstring); submitYear = submitDateVec[0]; submitMonth = submitDateVec[1]; submitDay = submitDateVec[2]; // process the following lines string str; while (getline(cin, str)) { carsMaintain(str); } // print the results printOut(); return 0; }
相关文章推荐
- 顺丰科技2018校园招聘在线笔试题
- 【中国大学mooc—浙江大学数据结构2018春】1.3节求最大子列和问题,算法3的实现(对应作业题目:01-复杂度1 最大子列和问题)
- 今日头条2018春季校园招聘研发岗位笔试编程题1
- 2015_12_27微软校园招聘笔试题目
- 算法思维——字符串压缩程序(华为2014校园招聘的机试题目)
- 网易2018校园招聘:魔法币 [python]
- 各大IT公司2012校园招聘笔试题目
- (2013PPS校园招聘杭州站)PPS研发类笔试题目
- 微软2016校园招聘9月在线笔试-题目3 : Fibonacci
- 2015年校园招聘之腾讯(数据挖掘)笔试面试题目
- 2012届华为校园招聘上机考试题目1(9月6日下午1点场)
- 2012届华为校园招聘上机考试题目——自己也尝试了下
- 2012届华为校园招聘上机考试题目--成都
- 微软2016校园招聘在线笔试题目-第一题 Magic Box
- 2012届华为校园招聘上机考试题目及参考代码
- 带信号灯的最短路dijkstra问题(阿里巴巴2018校园招聘算法题)
- 华为校园招聘笔试题(机考题目)
- 题目1531:货币面值(网易游戏2013年校园招聘笔试题)
- 2014华为校园招聘上机测试题目(华科提前批)
- 2012 届华为校园招聘上机考试题目(9 月 6 日下午 1 点场)