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

推荐订阅源

WordPress大学
WordPress大学
V
Visual Studio Blog
P
Privacy International News Feed
月光博客
月光博客
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
Lohrmann on Cybersecurity
N
News and Events Feed by Topic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
Webroot Blog
Webroot Blog
T
Threatpost
宝玉的分享
宝玉的分享
The Last Watchdog
The Last Watchdog
小众软件
小众软件
L
LINUX DO - 最新话题
C
Cisco Blogs
T
Troy Hunt's Blog
Schneier on Security
Schneier on Security
酷 壳 – CoolShell
酷 壳 – CoolShell
www.infosecurity-magazine.com
www.infosecurity-magazine.com
雷峰网
雷峰网
G
GRAHAM CLULEY
有赞技术团队
有赞技术团队
Know Your Adversary
Know Your Adversary
博客园 - 叶小钗
罗磊的独立博客
V
V2EX
博客园 - Franky
P
Proofpoint News Feed
SecWiki News
SecWiki News
腾讯CDC
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
博客园 - 三生石上(FineUI控件)
S
Secure Thoughts
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
PCI Perspectives
PCI Perspectives
V2EX - 技术
V2EX - 技术
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI
aimingoo的专栏
aimingoo的专栏
Cisco Talos Blog
Cisco Talos Blog
N
News and Events Feed by Topic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
SegmentFault 最新的问题

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