一亩三分地论坛

 找回密码
 获取更多干货,去instant注册!

扫码关注一亩三分地公众号
查看: 1649|回复: 4
收起左侧

Fidessa OA1 OA2 4月

[复制链接] |试试Instant~ |关注本帖
小翔926 发表于 2016-4-15 02:57:26 | 显示全部楼层 |阅读模式

2016(4-6月) 码农类 硕士 实习@Fidessa - 网上海投 - 在线笔试 |Otherfresh grad应届毕业生

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看,没有帐号?获取更多干货,去instant注册!

x
本帖最后由 wrj5518 于 2016-4-16 05:10 编辑

刚做完OA2 把OA1和2的问题+答案都post出来吧~ 攒人品。
/******************************************************************* 叫我分割线********************************************************************************/
Intern Pre-Screen(OA1)
第一题是找到重复字符对里属于重复字符对的第一个字母……是不是很难理解……也就是ABBA返回第一个A。
不说了,上代码。这个题输入输出自己研究一下……提前
  1. char findFirstRepeatingChar(string s) {
  2.     vector<int> record (128, 0);
  3.     for(int i = 0; i < s.size(); ++i) {
  4.         record[(int)s[i]]++;
  5.     }
  6.     for(int i = 0; i < s.size(); ++i) {
  7.         if(record[(int)s[i]] > 1)
  8.             return s[i];
  9.     }
  10.    
  11.     return ' ';
  12. }
复制代码
第二题判断一个三角形是不是等腰三角形,等边三角形或者不是三角形和其他三角形……额 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
不说了,上代码。
  1. #include <iostream>. from: 1point3acres.com/bbs
  2. using namespace std;
  3. int main() {
    . 1point 3acres 璁哄潧
  4.     /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  5.     int lines;
  6.     cin >> lines;
  7.     for(int i = 0; i < lines; ++i) {. From 1point 3acres bbs
  8.         int a, b, c;. visit 1point3acres.com for more.
  9.         cin >> a >> b >> c;
  10.         //illegal check
  11.         if(a < 0 || b < 0 || c < 0) { 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  12.             cout << "None of these" << endl;
  13.             continue;
  14.         }
  15.         // classify. 鍥磋鎴戜滑@1point 3 acres
  16.         if(a + b <= c || b + c <= a || a + c <= b)
  17.             cout << "None of these" << endl;
  18.         else if(a == b && b == c)
  19.             cout << "Equilateral" << endl;
  20.         else if(a == b || b == c || a == c)
  21.             cout << "Isosceles" << endl;
  22.         else
  23.             cout << "None of these" << endl;
  24.     }
  25.     return 0;. from: 1point3acres.com/bbs
  26. }
复制代码
/******************************************************************* 叫我分割线********************************************************************************/. From 1point 3acres bbs
Fidessa C++ Development Test 7 (Intern)
楼主做完……趴的HTML趴出来……噗……不让点右键复制……逗我呢?
第一题 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
At an airport, you have a timetable for arrivals and departures. You need to determine the minimum number of gates you’d need to provide so that all the planes can be placed at a gate as per their schedule.

The arrival and departure times for each plane are presented in two arrays, sorted by arrival time, and you’re told the total number of flights for the day.  Assume that no planes remain overnight at the airport; all fly in and back out on the same day.  Assume that if a plane departs in the same minute as another plane arrives, the arriving plane takes priority (i.e. you'll still need the gate for the departing plane); Write a function that returns the minimum number of gates needed for the schedules you're given.

Example:
arr[] = {900, 940, 950, 1100, 1500, 1800}
dep[] = {910, 1200, 1120, 1130, 1900, 2000}
. visit 1point3acres.com for more.
flights = 6

In this example the return value should be 3 since the schedules for at most 3 planes overlap.. visit 1point3acres.com for more.
Arrive 9:00 -> 1 gate
Depart 9:10 -> 0 gates
Arrive 9:40 -> 1 gate
Arrive 9:50 -> 2 gates. visit 1point3acres.com for more.
Arrive 11:00 -> 3 gates
Depart 11:20 -> 2 gates
Depart 11:30 -> 1 gate
Depart 12:00 -> 0 gates
Arrive 15:00 -> 1 gate.1point3acres缃
Arrive 18:00 -> 2 gates
Depart 19:00 -> 1 gate
Depart 20:00 -> 0 gates. 1point3acres.com/bbs
. 1point3acres.com/bbs
不说了,直接蹦代码……
  1. . visit 1point3acres.com for more.
  2. int findMinGates(vector < int > arrivals, vector < int > departures, int flights) {
  3.     sort(arrivals.begin(), arrivals.end());
  4.     sort(departures.begin(), departures.end());
  5.    
  6.     int res = 1, max = 1;
  7.     int i = 1, j = 0;
  8.    
  9.     while (i < flights && j < flights) {
  10.         if (arrivals[i] <= departures[j]) {
  11.             ++res;
  12.             if (res > max) {
  13.                 max = res;. more info on 1point3acres.com
  14.             }
  15.             ++i;
  16.         }
  17.         else {
  18.             --res;
    . 1point 3acres 璁哄潧
  19.             ++j;
  20.         }
  21.     }. 鍥磋鎴戜滑@1point 3 acres
  22.     return max;. Waral 鍗氬鏈夋洿澶氭枃绔,
  23. }
复制代码
第二题
You are given a String, input , comprised of alphabetical letters with varying case.

These letters should create pairs with one another, based on case.  For example, the letter 'A' forms a "matching pair" with the letter 'a', in that order

Rules:
The first letter must be upper-case.
. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴Every upper-case letter must be followed by its lower-case version or any upper-case letter.
When an upper-case letter is followed by its lower-case version, those two letters are considered a "matching pair" and can then be disregarded  from further match consideration.
If any of these rules are broken or a lower-case letter is encountered that does not create a "matching pair" with its nearest un-matched left neighbour, that letter and all following letters are considered "un-matched".

Output:. more info on 1point3acres.com
Your method should return the zero-based index of the last matching lower-case letter, or -1 if no pairs exist.

Limits:
0 < input length < 10,000 characters
The optimal method has a running time of O(input length).

Sample input #1
ABba
Sample output #1
3.鏈枃鍘熷垱鑷1point3acres璁哄潧
Sample explanation #1. 鍥磋鎴戜滑@1point 3 acres
'A' is an upper-case letter.
'A' is followed by an upper-case letter, 'B'.
'B' is followed by its lower-case version 'b' and form a "matching pair".
'a' forms a "matching pair" with 'A' ('B' and 'b' are already matched and therefore are disregarded).
Last matching index is 3.

Sample input #2. from: 1point3acres.com/bbs
ABbCca. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
Sample output #2
5
Sample explanation #2. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
'A' is an upper-case letter.
'A' is followed by an upper-case letter, 'B'.
'B' is followed by its lower-case version 'b' and form a "matching pair".
'b' is followed by any upper-case letter, 'C'.
'C' is followed by its lower-case version 'c' and form a "matching pair".
'a' forms a "matching pair" with 'A' ('B', 'b' and 'C', 'c' are already matched and therefore are disregarded).
Last matching index is 5.w.鐣欏璁哄潧-涓浜-涓夊垎鍦

Sample input #3. From 1point 3acres bbs
ABbba
Sample output #3
2
Sample explanation #3
'A' is an upper-case letter.
'A' is followed by an upper-case letter, 'B'.
'B' is followed by its lower-case version 'b' and form a "matching pair".
'b' does not pair with 'A' ('B' and 'b' are already matched and therefore are disregarded), therefore index 3 and all following letters are 'un-matched'.
Last matching index is 2.
  1. int findMatchingPair(const string& input) {
  2.     int res = -1;
  3.     vector<char> S;
  4.     for(int i = 0; i < input.size(); ++i) {
  5.         if(!isalpha(input[i])) break;. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
  6.         
  7.         if(isupper(input[i])) {
  8.             S.push_back(input[i]);
    . more info on 1point3acres.com
  9.         }.鏈枃鍘熷垱鑷1point3acres璁哄潧
  10.         else {.1point3acres缃
  11.             if(S.empty()) break;
  12.             else {
  13.                 if(S.back() == toupper(input[i])) {
  14.                     res = i;
  15.                     S.pop_back();
  16.                 }
  17.                 else 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  18.                     break;
  19.             }
  20.         }
  21.     }. visit 1point3acres.com for more.
  22.     return res;
  23. }
复制代码
……不知道怎么代码在这里格式这么奇怪……大家拿去自己调调吧 IDE里面

. from: 1point3acres.com/bbs










评分

3

查看全部评分

 楼主| 小翔926 发表于 2016-4-15 03:03:15 | 显示全部楼层
重新发下第一个代码……第一次发帖不太会~~大家见谅啊
  1. char findFirstRepeatingChar(string s) {
  2.     vector<int> record (128, 0);
  3.     for(int i = 0; i < s.size(); ++i) {
  4.         record[(int)s[i]]++;. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
  5.     }
  6.     for(int i = 0; i < s.size(); ++i) {
  7.         if(record[(int)s[i]] > 1)
  8.             return s[i];. visit 1point3acres.com for more.
  9.     }
  10.    
  11.     return ' ';. 1point3acres.com/bbs
  12. }
复制代码

评分

1

查看全部评分

回复 支持 反对

使用道具 举报

OverGhost 发表于 2016-4-15 06:00:56 | 显示全部楼层
怒谢楼主!
Flight Gate 那道题的解法很有意思。
回复 支持 反对

使用道具 举报

 楼主| 小翔926 发表于 2016-4-15 06:02:36 | 显示全部楼层
OverGhost 发表于 2016-4-14 14:00. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
怒谢楼主!
Flight Gate 那道题的解法很有意思。

两种做法啊 一种就是这个 双指针 另一种就是做个数据结构 遍历…… 遇到来的+1 走的-1
回复 支持 反对

使用道具 举报

 楼主| 小翔926 发表于 2016-4-15 06:03:25 | 显示全部楼层
拿到video面……继续努力……
回复 支持 反对

使用道具 举报

本版积分规则

请点这里访问我们的新网站:一亩三分地Instant.

Instant搜索更强大,不扣积分,内容组织的更好更整洁!目前仍在beta版本,努力完善中!反馈请点这里

关闭

一亩三分地推荐上一条 /5 下一条

手机版|小黑屋|一亩三分地论坛声明 ( 沪ICP备11015994号 )

custom counter

GMT+8, 2016-12-6 16:48

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

快速回复 返回顶部 返回列表