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

推荐订阅源

月光博客
月光博客
D
Docker
腾讯CDC
J
Java Code Geeks
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
博客园 - 三生石上(FineUI控件)
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
IT之家
IT之家
WordPress大学
WordPress大学
M
MIT News - Artificial intelligence
爱范儿
爱范儿
Microsoft Azure Blog
Microsoft Azure Blog
Vercel News
Vercel News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
小众软件
小众软件
N
Netflix TechBlog - Medium
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
博客园 - 【当耐特】

博客园 - 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;
}