zoukankan      html  css  js  c++  java
  • amazon 2013校园招聘题目

      下面是amazon 2013校园招聘题目,望大家贴现自己的答案哈,我准备收集笔试面试题。

    Amazon Hiring Campus 2013 - Final 6
    consider a kind of configuration file in amazon sofeware system. this kind of configuration file's format looks like this:
    B=10;
    A={
      A=100;
      B=BDE;
      C=C;
      D={
         A=windows;
         B=mac;
         C={
           A=redhat;
           B=ubuntu;
          };
     };
    A+={
     A=200;
     E=1000;
    };
    to repsent the key of the configuration, we use period(.) delimated method. for example,A.B represents the element B in Map A, and  the value of A.B is BDE; similarly,  the value of A.D.C.A is redhat. the the represent string is called 'path expression'. 
    the configuration also support append and override operation. for the above example, we use += operation to append or override the value in Map A. now the value of A.A is 200, and the value of A.E is 1000;
    Now, given a configuration strings and the key path of configuration, please return the value of configuration based the configuration strings. 
    
     Rules
    1)  the key name and his value only contains alphabet(A-Z,a-z) and number(0-9), no other charcters; 
    2) if cannot find the value or the expression point to a map, please output "N/A"
    3) if find the value, please output the value. no spaces when output the value. 
     
    Input and Output
    there are three part sin the input. the first line contains two integers indicates  the number of congiruation lines(M) and the number of expressions(N).
    M<=100, N<=100. the following M lines are the confugration and the last N lines are expression. every configuration line contains one or more configurations. every line length less than 1000. 
    Input :
    2 2
    A={A=1;B=2;C=3;E={A=100;};};
    A+={D=4;E={B=10;C=D;};};
    A.E.B
    B.D.E
    Output 
    A.E.B=10
    B.D.E=N/A
    
    
    
    
    
    #include <stdio.h>
    #include <string.h>
    #include <malloc.h>
    void calculateAndPrint(char* confs[], int confLength, char* exs[] , int exLength){
        //Your Code is here
    }
    int main(){
        int confLength=0; 
        int exLength=0;
        scanf("%d %d\n",&confLength, &exLength);
        char* confs[10];
        char* exs[10];
        int i=0;
        for(i=0;i<confLength;i++){
            char* data = (char*)malloc(1000*sizeof(char));
            gets(data);
            confs[i] = data;
        }
        for(i=0;i<exLength;i++){
            char* data = (char*)malloc(1000*sizeof(char));
            gets(data);
            exs[i] = data;
        }
        calculateAndPrint(confs,confLength,exs,exLength);
        for(i=0;i<confLength;i++){
            free(confs[i]);
        }
        for(i=0;i<exLength;i++){
            free(exs[i]);
        }
        return 0;
    } 
    
    
    
    
    •    Question 1 / 2
    Let's assume that there is a simple market for beans. Every day there is a published bean price in the market. Traders can buy or sell at the published price. There is a trader who time travelled to future and brought back the price information for a number of days in the future. If you have this information and you are allowed to buy and sell many times. How do you make the maximum profit? The price information will be given as an array of numbers. Each number is for a day’s trading price. The numbers are all integers to simplify the problem. You will need to return the index of the buy-in point and sell-out point for maximum profit.
    Rules:
    1) The input line length less than 1000, and the trading price length less than 100;
    2) The trading price is positive integer;
    3) The trading prices are delimited  by ' '(single space);
    4) Please make sure every buying and selling period shortest. especially, please ouput '-' if all the trading prices are the same or no trading point;
    Sample Input and Output:
    Input 1
    1 3 5 4 2 8 10
    Output 1
    1 3 5 7
    To make the maximum profit, you should buy at $1 and sell at $5, and then buy at $5 and sell it at $10. so the output is "1 3 5 7".
    Input 2 
    1 1 1 3 5 4 2 2 2 8 10
    Ouput 2
    3 5 9 11 
     
    
    include <iostream>
    #include <cstring>
     
    using namespace std;
     
     
    void calculateAndPrint(int array[], int length)
    {
        //Your Code is here
        const int halflen = length / 2;
        int buy_index[halflen];
        int sell_index[halflen];
        memset(buy_index, 0, halflen);
        memset(sell_index, 0, halflen);
        
        int sum = 0;  
     
        int b = 0;  
        
        int i = 0;
        int j = 0;
        int k = 0;
        for(; i < length; i = j +1)  
        {  
            for(j = i; i <length; j++)
            {
                b = array[j] - array[i];
                if(b < 0) 
                {
                    b = array[i];  
                }
                else
                {
                    b += array[i]; 
                }
                if(sum < b) 
                {
                    sum = b; 
                    buy_index[k] = i;
                    sell_index[k] = j;
                    k++;
                }
            }
        } 
     
        if(k >0)
        {
            for(i = 0; i < k; i++)
            {
                cout<<buy_index[k]<<" "<<sell_index[k]<<" ";
            }
            cout<<endl;
        }
        else
        {  
            cout<<"-";
        }
    }
     
    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(gets(line))
        {
            int array[100] = {0};
            int length = splitAndConvert(line,array);
            if(length==0)
            {
                break;
            }
            calculateAndPrint(array, length);
            cout<<endl;
        }
        return 0; 
    } 
  • 相关阅读:
    微信小程序 iPhone 11、iPhoneX 底部安全区域(底部小黑条)适配
    Servlet与vue-axios交互跨域问题之Access-Control-Allow-Origin' header contains multiple values '*, null', but only one is allowed.
    Windows10下PCL1.8.1以及Python-pcl1.81环境配置的掉发之路
    【问题记录】Navicat Premium连接mysql-8.0.17时出现2059
    mysql-8.0.17解压版安装步骤及MySQL服务无法启动问题的解决办法
    ENVI基本操作之彩色合成
    GeoServer与Udig发布矢量数据出现的问题1——预览数据一半显示正常一半重叠
    本地日志文件
    SQL语句(2)--- 函数
    SQL语句(1)--- SQL简介
  • 原文地址:https://www.cnblogs.com/danshui/p/2731540.html
Copyright © 2011-2022 走看看