以下题目是在投递华为外包的时候收到邮件要求自己学习的算法,具体题目也不太清楚,都是从网上搜到的,然后大概搞了一下答案,主要是想让自己看起来方便一些。
1.航班预订座位数(来自leetcode)
参考链接:https://leetcode-cn.com/problems/corporate-flight-bookings/
class Solution {
public:
vector corpFlightBookings(vector>& bookings, int n) {
vector res(n+1,0);
for(auto &b :bookings){
res[b[0]-1]+=b[2];
res[b[1]]-=b[2];
}
for(int i=1;i
或者有可能是题目如下:
给定多组原本的航班预订信息(航班号,座位号,乘客姓名),以及多组要改签的航班信息(原本航班号,原本座位号,新航班号,新座位号)
输出最后的航班预订信息,要是有重复的内容,以最新改签的为标准
输入的内容如下: 3 表示原本的航班信息数,2表示要改签的航班数
3
CZ7132,A1,ZHANGSAN
CZ7132,A2,ZHAOSI
CZ7156,A2,WANGWU
2
CZ7132,A1,CZ7156,A2
CZ7156,A2,CZ7156,A3
输出内容如下:
CZ7132,A2,ZHAOSI
CZ7156,A2,ZHANGSA
CZ7156,A3,WANGW
参考链接:https://blog.csdn.net/Kyrie001/article/details/102459731
//
// main.cpp
// huawei
//
// Created by Apple on 2020/2/29.
// Copyright © 2020年 Apple. All rights reserved.
//
#include
#include
#include
#include
using namespace std;
int main(int argc, const char * argv[]) {
int n1;
map<string,string > data;
map<string,string > coutdata;
map<string,string > updatedata;
map <string, string>::iterator a,b;
cin>>n1;
getchar();
cout<<n1<<endl;
for(int i=0;i<n1;i++){
string str1;
cin>>str1;
cout<<str1<<endl;
int a,len;
a=str1.rfind(",");
len=str1.length();
string left,right;
left=str1.substr(0,a);
right=str1.substr(a+1,len-a-1);
data.insert(pair<string,string>(left,right));
}
int n2;
cin>>n2;
cout<<n2<<endl;
for(int j=0;j<n2;j++){
string str2;
cin>>str2;
cout<<str2<<endl;
int e=0;
int count=0;
for(int k=0;k<str2.length();k++){
if(str2[k]==','){
count++;
if(count==2){
e=k;
cout<<e<<endl;
}
}
}
string uleft,uright;
uleft=str2.substr(0,e);
uright=str2.substr(e+1,str2.length()-e-1);
updatedata.insert(pair<string,string>(uleft,uright));
}
for(a=data.begin();a!=data.end();a++){
for(b=updatedata.begin();b!=updatedata.end();b++){
if(a->first==b->first){
//data.erase(a->second);
//data.erase(a->first);
//data.insert(pair(b->second,a->second));
coutdata.insert(pair<string,string>(b->second,a->second));
break;
}else{
coutdata.insert(pair<string,string>(a->first,a->second));
}
}
}
for(a=coutdata.begin();a!=coutdata.end();a++){
cout<<a->first<<a->second<<endl;
}
/* 3
CZ7132,A1,ZHANGSAN
CZ7132,A2,ZHAOSI
CZ7156,A2,WANGWU
2
CZ7132,A1,CZ7156,A2
CZ7156,A2,CZ7156,A3
CZ7132,A2,ZHAOSI
CZ7156,A2,ZHANGSA
CZ7156,A3,WANGW
*/
//cout << "Hello, World!\n";
return 0;
}
2.JS如何判断一组数据是否连续
//判断一串数字是否是连续的
function isContinuityNum(num){
let array=[];
if(num instanceof Array){
array = [...num];
}else{
array = Array.from(num.toString())//转换为数组
}
var i=array[0];
var isContinuation=true;
for(var e in array){
if(array[e]!=i){
isContinuation=false;
break;
}
i++;
}
return isContinuation;
}
参考:https://blog.csdn.net/qq_24298751/article/details/102717351
3.九宫格按键输入
转自:https://blog.csdn.net/Stydwn/article/details/87970115?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
#include
#include
#include
#include
#include
using namespace std;
string s[10]={"0 ","1,.?!","2ABC","3DEF","4GHI","5JKL","6MNO","7PQRS","8TUV","9WXYZ"};
int main()
{
string a,ch="";
getline(cin,a);
for(int i=0;i<a.size() ;i++)
{
if(i==a.size() -1)
ch+=a[i];
if(a[i]!=' '&&i!=a.size() -1)
{
ch+=a[i];
}
else
{
int k=(ch[0]-48);
int t=ch.size() ;
//cout<
t=(t-1)%s[k].size() ;
cout<<s[k][t];
ch="";
}
}
}