ThoughtWorks思特沃克2018校园招聘之春招家庭作业 - 无人机
2018-03-19 23:55
323 查看
题目要求:
这里给出我的Readme文档就好了,里面有详细说明,这也仅供参考。
Readme:
这里给出我的Readme文档就好了,里面有详细说明,这也仅供参考。
Readme:
代码
#include <bits/stdc++.h> using namespace std; struct Point { int x, y, z; bool isOk; Point() {} Point(int x, int y, int z, bool isOk) : x(x), y(y), z(z), isOk(isOk) {} }; #define MAX_SIZE (1 << 12) int main() { // 打开两个输入的文件 FILE *fp1 = fopen("in", "r"); FILE *fp2 = fopen("in2", "r"); // 输入询问序号,并对其进行排序去重,使得处理工作可以方便进行 vector<int> tag; for (int x; EOF != fscanf(fp2, "%d", &x); tag.push_back(x)) {} sort(tag.begin(), tag.end()); tag.erase(unique(tag.begin(), tag.end()), tag.end()); // 关闭第二个文件 fclose(fp2); fp2 = NULL; // 使用map可以处理多个无人机 int top = 0; map<string, Point> mp; char s[MAX_SIZE]; for (int index = 0; EOF != fscanf(fp1, "%s", s); index++) { bool f = false; int x, y, z, offsetX, offsetY, offsetZ; fscanf(fp1, "%d%d%d", &x, &y, &z); if (fgetc(fp1) != '\n') fscanf(fp1, "%d%d%d", &offsetX, &offsetY, &offsetZ), f = true; if (mp.find(s) == mp.end()) { if (!f) mp[s] = Point(x, y, z, true); else mp[s] = Point(0, 0, 0, false); } else { if (mp[s].isOk && mp[s].x == x && mp[s].y == y && mp[s].z == z) { mp[s] = Point(x + offsetX, y + offsetY, z + offsetZ, true); } else mp[s].isOk = false; } if (tag[top] == index) { if (!mp[s].isOk) printf("Error: %d\n", index); else printf("%s %d %d %d %d\n", s, index, mp[s].x, mp[s].y, mp[s].z); ++top; } } // 剩下的询问一定是超过序号的,因此,依次输出 for (; top < (int)tag.size(); ++top) printf("cannot find %d\n", tag[top]); fclose(fp1); fp1 = NULL; return 0; }
思路
代码中已经有详细注释了单元测试样例
对于输入文件in, in2,如果能得出stdout, 那么就是正确的。样例1
in
plane1 1 1 1 plane1 1 1 1 1 2 3 plane1 2 3 4 1 1 1 plane1 3 4 5 plane1 1 1 1 1 2 3
in2
2 2 4 100
stdout
plane1 2 3 4 5 Error: 4 cannot find 100
样例2
in
plane1 1 1 1 plane1 1 1 1 1 2 3 plane1 2 3 4 1 1 1 plane2 3 4 5 plane1 1 1 1 1 2 3
in2
3 2 4 100
stdout
plane1 2 3 4 5 plane2 3 3 4 5 Error: 4 cannot find 100
相关文章推荐
- ThoughtWorks 2018校园招聘作业题目 -- 出租车
- ThoughtWorks公司2014校园招聘作业题
- ThoughtWorks公司2014校园招聘作业题
- ThoughtWorks公司2014校园招聘作业题
- [转]阿里巴巴集团2014秋季校园招聘笔试题
- 多益网络2015校园招聘面试题目大揭秘
- 百度2015校园招聘一、二、三面面试经历(软件研发岗)
- 腾讯2011.10.15校园招聘会笔试题
- 中科创达2015校园招聘Java卷的笔试题及附加题答案
- 腾讯2014校园招聘2013.10.26杭州笔试题
- 百度2015校园招聘笔试题——研发工程师(西安站)
- 360公司2015年秋季校园招聘笔试考卷(技术类 D)部分试题程序验证和解析7
- IT企业校园招聘软件测试岗基本要求
- 软件测试工程师-meitu(2014年校园招聘笔试)
- 微软2016校园招聘在线笔试 B Professor Q's Software [ 拓扑图dp ]
- 海康威视2014校园招聘C++笔试题
- 雷文-武汉科技大学-软件工程-本科-20111020(2011年校园招聘找工作时的简历)
- 十月下旬腾讯,网易游戏,百度迅雷校园招聘笔试题集锦(第271-330题)
- 【飞牛网2015校园招聘】WEB前端开发工程师 笔试题
- 百度2015校园招聘面试题