2016校招编程题<一>
来源:互联网 发布:java aes加密 key iv 编辑:程序博客网 时间:2024/06/04 21:23
一个长度为N的数组中包含正数,负数和0,请实现一个函数找出最长和为零的连续子数组。
输入:所有数组元素在一行,空格隔开
输出:所有数组元素在一行,空格隔开
输出:所有数组元素在一行,空格隔开
输入样例:1 2 3 4 -1 -2 -4 -3 1 2
输出样例:1 2 3 4 -1 -2 -4 -3
<span style="font-size:18px;">#include <iostream>#include <vector>#include <string>using namespace std;int main(){string str;getline(cin, str);vector<int> arr;vector<int> sum;int sumIndex = 0;sum.push_back(0);int index = 0;int nextIndex = 0;int n;string tmp;while(index != -1){if(index == 0){nextIndex = str.find(' ', index);tmp = str.substr(index, nextIndex-index);}else{nextIndex = str.find(' ', index+1);tmp = str.substr(index+1, nextIndex-index-1);}int itemp = std::atoi(tmp.c_str());arr.push_back(itemp);n = itemp + sum[sumIndex];sum.push_back(n);sumIndex++;index = nextIndex;}int minIndex = 0;int maxIndex = 0;int maxLen = 0;for (int i = 0; i < sum.size(); i++){for (int j = sum.size()-1; j > i + maxLen; j--){if(sum[i] == sum[j]){maxLen = j - i;minIndex = i;maxIndex = j;}}}for (int i = minIndex; i < maxIndex; i++){cout << arr[i] << ' ';}return 0;}</span>
0 0
- 2016校招编程题<一>
- 2016 360校招笔试编程题
- 京东2016校招编程题
- 2016校招编程题<二>
- 2016校招编程题<三>
- 2016校招编程题<四>
- 滴滴出行2016校招编程题
- 京东2016校招编程题
- 2016校招编程题汇总
- 校招编程题集锦
- 2015秋季美团校招研发题编程题一
- 腾讯2017秋招笔试编程题(一)
- 美图2016校招java编程
- 2016 ThoughtWorks 校招编程作业
- 2016校招编程 lcs 动态规划
- 迅雷2014校招编程题
- 京东2015校招笔试编程题
- 360校招编程题:内存管理
- oracle中的空值问题2 -- null!=null
- Java并发编程实践之Callable,Future,RutureTask的使用
- 关于Logcat在真机调试时没有输出的问题
- 爬取淘宝MM图片
- 飞秋基本udp通信
- 2016校招编程题<一>
- kali linux wpscan wordpress
- WLGK-51单片机接口技术基础实验 —LED闪烁灯
- Fraction to Recurring Decimal
- 鸟哥的Linux私房菜基础篇第三版 -- 目录
- 2016校招编程题<二>
- 黑马程序员——C语言基础---循环结构
- FloatingActionButton,TextInputLayout,Snackbar,TabLayout
- 2016校招编程题<三>