//
// main.cpp
// pdd
//
// Created by 吴珝君 on 2019/3/11.
// Copyright © 2019年 闲着也是贤者. All rights reserved.
//
#include <iostream>
#include <string>
#include <vector>
//找最小序的第一个字符
using namespace std;
int findfirst(string str)
{
if (str.empty())
{
return -1;
}
int arr[26] = {0};
vector<char> vchar;//
for (int i =0 ; i < str.length(); i++)
{
if (str[i] >='A' && str[i]<='Z')
{
str[i] = str[i] +32;
}
}//处理字符串
for (int i =0 ; i < str.length(); i++)
{
if (arr[str[i] -'a'] ==0)
{
arr[str[i] -'a'] =1;
vchar.push_back(str[i]);
}
else
{
vector<char>::iterator it = find(vchar.begin(), vchar.end(), str[i]);
vector<char>::iterator t = it;
if (++t!=vchar.end())//当前字符是最后一个字符
{
if (*it >= *t)
{
vchar.erase(it);//删除当前字符
vchar.push_back(str[i]);
}
}
}
}
for (int i =0; i < vchar.size(); i++)
{
cout << vchar[i]<<" ";
}
cout << vchar[0];
return 0;
}
int main(int argc, const char * argv[]) {
// insert code here...
findfirst("xabXY");
findfirst("aa");
std::cout << "Hello, World!\n";
return 0;
}
//
// main.cpp
// pdd
//
// Created by 吴珝君 on 2019/3/11.
// Copyright © 2019年 闲着也是贤者. All rights reserved.
//
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
//找最小序的第一个字符
using namespace std;
//robbank
class position_bank
{
public:
int num_position;
int num_money;
position_bank(int position, int money)
{
num_position = position;
num_money = money;
}
position_bank( const position_bank & pb)
{
this->num_money = pb.num_money;
this->num_position = pb.num_position;
}
};
bool operator<(position_bank pb1,position_bank pb2)
{
return pb2.num_money < pb1.num_money;//从大到小排序饿
}
int robbank(vector<position_bank> vbank , int d)
{
int sum =0;
sort(vbank.begin(), vbank.end());
int t = 0;
for (int i =0; i < vbank.size(); i++)
{
for (int j = i+1; j < vbank.size(); j++)
{
if (abs(vbank[i].num_position - vbank[j].num_position)>=d )
{
t = vbank[i].num_money +vbank[j].num_money;
break;
}
}
sum = sum > t? sum :t;
}
cout << sum;
return 0;
}
int main(int argc, const char * argv[]) {
// insert code here...
int number =0,d =0;//银行个数
cin >> number;
cin >> d;
vector<position_bank> vbank;
for (int i =0; i < number; i++)
{
int position =0;
int money = 0;
cin >>position ;
cin >> money;
position_bank pb(position, money);
vbank.push_back(pb);
}
robbank(vbank, d);
std::cout << "Hello, World!\n";
return 0;
}