招银网络笔试总结

又被虐了,可恶的是它居然还出了几道java,jvm,web,xml的题。虽然心里面已经又准备,但心里无疑又增添了不少紧迫感。无论如何,一直总结才是前进的王道,加油呀!

先来回顾一道编程题,讲道理,这道编程题出得好烂啊,不知所云,也无法测试,而且返回什么也不说清楚。题目说,招行网络要去外面拿订单,有三个办公室,每个办公室有自己的权重:
JB01 1;
JB02 2;
JB03 1;
而且这些办公室拿一轮订单就结束了,剩下的订单可以先抛弃。要你写一个函数,实参一个订单的ID列表(我就姑且认为是顺序容器vector吧)和map的权重表,这个函数返回每个办公室的订单表。

#include <vector>
#include <iostream>
#include <string>
#include <map>

using namespace std;
void allocate(vector<string> ID, map<string,int> weight, map<string,vector<string>> &temp){
    int i=0;
    for(auto &w:weight){
        vector<string> t;
        while(w.second){
            t.push_back(ID[i++]);
            --w.second;
        }
        temp.insert(make_pair(w.first,t));
    }
}

int main(){
    map<string,int> weight{{"JB01",1},{"JB02",2},{"JB03",1}};
    vector<string> ID{"11","22","33","44","55"};
    string word;
    map<string,vector<string>> temp;
    allocate(ID,weight,temp);
    cout<<"Please input your office:"<<endl;
    cin>>word;
    map<string,vector<string>>::iterator iter=temp.find(word);
    if(iter!=temp.end())
    {
        vector<string>::iterator it = iter->second.begin();
        while(it != iter->second.end())
        {
            cout<<(*it++)<<endl;  
        } 
    }
    return 0;
}                       

这个题目涉及到了map嵌套vector的示例(我个人认为),关联容器有很多灵活的使用方法,先来回顾一下关联容器的insert成员:向容器中添加一个元素的四种方法

map<string,size_t> word_count;
word_count.insert({word,1});
word_count.insert(make_pair(word,1));
word_count.insert(pair<string,size_t>)(word,1));
word_count.insert(map<string,size_t>::value_type(word,1));

解法中,我直接使用了make_pair去insert成员。在这里,map嵌套vector的关键其实是要将主键和已经创建好的一组向量去make_pair,而不能直接去push_back(),我前期也犯了很大的错误。其次,我们要用迭代器作为指针,然后解指针获得map的值。

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
招银网络Java笔试题主要测试对Java语言的理解和应用能力。以下是一些可能出现的题目和答案: 题目一:请用Java语言实现一个简单的计算器,能够进行加减乘除运算。 答案一: ```java import java.util.Scanner; public class Calculator { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("请输入第一个运算数:"); double num1 = input.nextDouble(); System.out.print("请输入第二个运算数:"); double num2 = input.nextDouble(); System.out.print("请输入运算符(+、-、*、/):"); char operator = input.next().charAt(0); double result = 0; switch (operator) { case '+': result = num1 + num2; break; case '-': result = num1 - num2; break; case '*': result = num1 * num2; break; case '/': result = num1 / num2; break; default: System.out.println("请输入正确的运算符!"); } System.out.println("计算结果:" + result); } } ``` 题目二:请写一个Java程序,判断一个字符串是否是回文串。 答案二: ```java import java.util.Scanner; public class Palindrome { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("请输入一个字符串:"); String str = input.next(); boolean isPalindrome = true; int length = str.length(); for (int i = 0; i < length / 2; i++) { if (str.charAt(i) != str.charAt(length - i - 1)) { isPalindrome = false; break; } } if (isPalindrome) { System.out.println(str + "是回文串"); } else { System.out.println(str + "不是回文串"); } } } ``` 以上是两道可能出现在招银网络Java笔试中的题目及其解答,供参考。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值