惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
宝玉的分享
宝玉的分享
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
博客园 - 司徒正美
酷 壳 – CoolShell
酷 壳 – CoolShell
IT之家
IT之家
H
Help Net Security
雷峰网
雷峰网
M
MIT News - Artificial intelligence
Microsoft Security Blog
Microsoft Security Blog
美团技术团队
GbyAI
GbyAI
博客园_首页
博客园 - 三生石上(FineUI控件)
T
Tailwind CSS Blog
I
InfoQ
小众软件
小众软件
Google DeepMind News
Google DeepMind News
D
Docker
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
博客园 - Franky
Hugging Face - Blog
Hugging Face - Blog

博客园 - Lunais

恢复 git stash drop 丢失的内容 Git技巧:彻底重置本地仓库与远程同步,同时保留Stash内容 信源编码和信道编码区别 Leetcode scanf 5G 3gpp协议 eclipse调试配置 find查找 浮点类型(float、double)在内存中的存储 yield [基础函数]memset用法 python2处理表格文件按照规则多行输出(中文路径,print) linux系统objdump输出动态库.so文件和静态库.a中符号表 python复制删除文件&修改目录&执行bat(wins) Linux C下的正则表达式 kill eclipse C语言之表达式运算整体提升 查找函数对比:findall,search,match Linux backtrace() git本地协同
一组数据差值之和最大
Lunais · 2023-08-03 · via 博客园 - Lunais
#include <bits/stdc++.h>
using namespace std;
class Solution{
    std::vector<std::string> split(std::string &str, char ch){
        std::vector<std::string> ans;
        str += ch;
        int i = 0;
        for (int j = 0; j < str.size(); ++j) {
            if(str[j] == ch){
                ans.push_back(str.substr(i, j - i));
                i = j + 1;
            }
        }
        return ans;
    }
public:
    int process(std::string str){
        std::vector<std::string> tmp = split(str, ' ');
        std::vector<int> prices;
     //string容器转int容器保存
for (int i = 0; i < tmp.size(); i++) { prices.push_back(atoi(tmp[i].c_str())); }   int min_ = prices[0], max_ = prices[0], answer = 0;   for (int i = 1; i < prices.size(); ++i) {//连续降序找到最小,然后连续升序找到最大。--循环 if (prices[i] < max_) { answer += max_ - min_; max_ = min_ = prices[i]; }
     else max_ = prices[i];   }   answer += max_ - min_;   return answer; } };

int main()
{
  // please write your code here
  std::string str, str1;
  getline(std::cin, str1);
  getline(std::cin, str);
  Solution a;
  std::cout << a.process(str);
  return 0;
}