注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
本帖最后由 wrj5518 于 2016-4-16 05:10 编辑
刚做完OA2 把OA1和2的问题+答案都post出来吧~ 攒人品。
/******************************************************************* 叫我分割线********************************************************************************/
Intern Pre-Screen(OA1)
第一题是找到重复字符对里属于重复字符对的第一个字母……是不是很难理解……也就是ABBA返回第一个A。
不说了,上代码。这个题输入输出自己研究一下……提前- char findFirstRepeatingChar(string s) {
- vector<int> record (128, 0);
- for(int i = 0; i < s.size(); ++i) {
- record[(int)s[i]]++;
- }
- for(int i = 0; i < s.size(); ++i) {
- if(record[(int)s[i]] > 1)
- return s[i];
- }
-
- return ' ';
- }
复制代码 第二题判断一个三角形是不是等腰三角形,等边三角形或者不是三角形和其他三角形……额
不说了,上代码。- #include <iostream>
- using namespace std;
- int main() {
- /* Enter your code here. Read input from STDIN. Print output to STDOUT */
- int lines;
- cin >> lines;
- for(int i = 0; i < lines; ++i) {
- int a, b, c;
- cin >> a >> b >> c;
- //illegal check
- if(a < 0 || b < 0 || c < 0) {
- cout << "None of these" << endl;
- continue;
- }
- // classify
- if(a + b <= c || b + c <= a || a + c <= b)
- cout << "None of these" << endl;
- else if(a == b && b == c)
- cout << "Equilateral" << endl;
- else if(a == b || b == c || a == c)
- cout << "Isosceles" << endl;
- else
- cout << "None of these" << endl;
- }
- return 0;
- }
复制代码 /******************************************************************* 叫我分割线********************************************************************************/
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 g, 'c' are already matched and therefore are disregarded).
Last matching index is 5.w
Sample input #3
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.- int findMatchingPair(const string& input) {
- int res = -1;
- vector<char> S;
- for(int i = 0; i < input.size(); ++i) {
- if(!isalpha(input[i])) break;
-
- if(isupper(input[i])) {
- S.push_back(input[i]);
- }
- else {
- if(S.empty()) break;
- else {
- if(S.back() == toupper(input[i])) {
- res = i;
- S.pop_back();
- }
- else
- break;
- }
- }
- }
- return res;
- }
复制代码 ……不知道怎么代码在这里格式这么奇怪……大家拿去自己调调吧 IDE里面
|