阿里在线笔试题---乱序到来顺序输出
来源:互联网 发布:c语言输出乘法口诀表 编辑:程序博客网 时间:2024/06/03 01:42
#include <bits/stdc++.h>using namespace std;const int maxLength = 1000;int arrayLength;int unsortedList[maxLength], sortedList[maxLength];void test() {srand((unsigned) time(NULL));arrayLength = rand() % maxLength + 1;for (int i = 0; i < arrayLength; i++)unsortedList[i] = sortedList[i] = rand() % 0x7fffffff + 1;}int main(void) {test();cout << "The length is : " << arrayLength << endl;cout << "The coming list is : " << endl;for (int i = 0; i < arrayLength; i++)cout << unsortedList[i] << " ";cout << endl << endl;map<int, bool> vstd;int counter = 1;int expectedIndex = 0, latestIndex = 0;sort(sortedList, sortedList + arrayLength);cout << "The Output is : " << endl;for (int i = 0; i < arrayLength; i++) {if (unsortedList[i] == sortedList[expectedIndex]) {int tempIndex = expectedIndex + 1;while (tempIndex < arrayLength && vstd[sortedList[tempIndex]])tempIndex++;latestIndex = tempIndex - 1;cout << counter << ":";counter++;for (int j = expectedIndex; j <= latestIndex; j++)cout << sortedList[j] << " ";cout << endl;expectedIndex = ++latestIndex;}vstd[unsortedList[i]] = true;}}
0 0
- 阿里在线笔试题---乱序到来顺序输出
- 阿里笔试题,乱序序列的保序输出。
- 2015阿里前端实习在线笔试题
- 阿里在线笔试算法工程师附加题
- 阿里在线笔试有感
- 阿里2015 在线笔试
- DS之顺序表实现乱序输入顺序输出
- java类初始化顺序-阿里笔试题
- java类初始化顺序-阿里笔试题
- java类初始化顺序-阿里笔试题
- java类初始化顺序-阿里笔试题
- 阿里2015 实习笔试题笔记 分布式系统中的RPC请求经常出现乱序的情况
- 阿里在线笔试-路径求和
- 阿里2015在线研发工程师笔试题(部分)
- 阿里在线笔试题 折半方法求最接近sum值
- 2015年阿里研发工程师实习在线笔试题
- 2016阿里在线笔试Java研发附加题
- 阿里秋招在线笔试两道编程题
- 【Objective-C学习笔记】核心语法——实例变量作用域、关键字@property和@synthesize
- json格式和php数组的相互转换
- 【Pyhton 笔记】--杂谈【0】
- webview的基本操作
- 总结-数据结构
- 阿里在线笔试题---乱序到来顺序输出
- 同一局域网内其它设备无法访问本地Apache问题的解决
- how to output quotes in bash prompt
- linux中bridge mode和NAT mode成功ping www.baidu.com必须注意检查核对的地方[操作系统为centos6.6版本]
- 杭电 HDU ACM 1390 Binary Numbers
- 今天开始,在此记录学习Linux嵌入式
- 历届试题 翻硬币
- Android恶意软件安装量2014年同比减半
- 黑马程序员——正则