【面试题】2013亚马逊校园招聘--在线笔试题
来源:互联网 发布:初中物理软件大全 编辑:程序博客网 时间:2024/04/28 14:29
第一题:
Question
We have an array representing customer’s shopping records.
For example, it’s an array like this:
custA, item1,
custB, item1,
custA, item2,
custB, item3,
custC, item1,
custC, item3,
custD, item2,
This array indicates that customer A bought item 1, customer B bought item 1, customer A bought item 2, customer B bought item 3, etc..
For a given item X and shopping records array, write code to find out what else (item Y) was bought mostly by the customers who bought item X.
For example, in above example, if X is item 1 then Y should be item 3.
Rules:
1. One customer can only buy one item once..
2. The mostly brought item should not be item X..
3. If no customer brought item X, then return “None”.
4.If all the customers who brought item X only brought item X, then return “None”.
5.The first line of input is the item X. The second line of input is the shopping record array, this shopping record array is split by space..
6. If there are many other mostly brought items which have equally brought times, then return any one of those items..
Examples:
Input1:
item1
custA item1 custB item1 custA item2 custB item3 custC item1 custC item3 custD item2
Output1:
item3
Input2:
item2
custA item1 custB item1 custC item1 custA item2 custB item3 custA item3
Output2:
item1
(The output2 can be item3 too)
简单的说就是买了X的人又买了其他的东西,那么其他这些东西中,买的数量最多的是哪个??
答案:
2、给定一个原始序列和一个经过push N次pop N次形成的出栈序列,求push和pop的次序??
运行结果是
1,2,3,4
2,4,3,1
push1 push2 pop2 push3 push4 pop4 pop3 pop1
我的程序:
#include <iostream>#include <cstring>#include <stack>using namespace std;void calculateOperationSequence(int *originalArray, int *resultArray, int length);inline bool isSpace(char x){ return x == ' ' || x == '\r' || x == '\n' || x == '\r' || x == '\b' || x == '\t';}char * rightTrim(char *str){ int len = strlen(str); while(--len>=0){ if(isSpace(str[len])){ str[len] = '\0'; }else{ break; } } return str;}char * getInputLine(char *buffer, int length){ if(fgets(buffer,length, stdin)==NULL){ return NULL; } rightTrim(buffer); if(strlen(buffer)<=0){ return NULL; } return buffer;}int splitAndConvert(char* strings,int *array){ char*tokenPtr = strtok(strings,","); int i=0; while(tokenPtr!=NULL){ array[i] = atoi(tokenPtr); i++; tokenPtr=strtok(NULL,","); } return i;}int main(){ char line[1000] = {0} ; while(getInputLine(line,1000)){ int originalArray[30] = {0}; int originalArrayLength = splitAndConvert(line,originalArray); if(originalArrayLength==0){ break; }getInputLine(line, 1000);int resultArray[30] = {0}; int resultArrayLength = splitAndConvert(line,resultArray); if(resultArrayLength==0){ break; }/*operationSequence = */calculateOperationSequence(originalArray, resultArray, resultArrayLength);/*cout<<operationSequence<<endl;*/ } return 0; } //your code is herevoid calculateOperationSequence(int *originalArray, int *resultArray, int length){int j = 0;int i = 0;stack<int> s;while( j<length && i<length){if(originalArray[i] != resultArray[j]){s.push(originalArray[i]);cout << "push"<<originalArray[i]<<" ";i++;if(i>length-1){break;}}else{cout <<"push"<<originalArray[i++]<<" ";cout <<"pop"<<resultArray[j++]<< " ";if(i>length-1 || j>length-1){break;}}}while(!s.empty() && j<length){if(s.top() == resultArray[j]){s.pop();cout << "pop"<<resultArray[j]<<" ";j++;}else{return ;}}}
- 【面试题】2013亚马逊校园招聘--在线笔试题
- 2013亚马逊校园招聘在线笔试题MM-Chess
- 【面试题】数码视讯---2013校园招聘---笔试题
- Amazon(亚马逊)2014届秋季校园招聘在线笔试题一
- 2013年阿里巴巴校园招聘笔试+面试题
- 仔仔细细做面试题---google2013校园招聘笔试题
- 【面试题】 迅雷2014校园招聘笔试题
- 2015华为校园招聘机试题+1道2013年网易校园招聘笔试题
- 2013年世界校园招聘笔试试题
- 2012IT公司校园招聘笔试面试题
- 2012IT公司校园招聘笔试面试题
- 新华三2018校园招聘笔试面试题学习
- 程序员面试题精选(38):2008百度校园招聘的一道笔试题
- [历年IT笔试题]2014腾讯校园招聘笔试试题
- [历年IT笔试题]2014微软校园招聘笔试试题
- 校园招聘模拟面试题
- 校园招聘笔试题
- 2017校园招聘腾讯笔试题 在线编程题
- 进程劫持
- XP系统下简单的清理系统盘(C盘)
- Qt基础学习(5)-----抽屉效果之QToolBox
- 冲出迷途:你真的了解分层架构吗?
- Android文件IO详解
- 【面试题】2013亚马逊校园招聘--在线笔试题
- 分段字符串,用逗号,但是最后一个就没有逗号
- 恢复xp欢迎界面
- 落花泪,与君诀
- Windows7下安装Oracle 10g提示“程序异常终止,发生未知错误”的解决方法
- 批量删除数据库表和内容
- 新版Kinect for windows SDK1.6.0发布
- 配置Linux开发环境
- Qt中停靠窗口的实现