微软2014实习生及秋令营技术类职位在线测试(题目1 : String reorder)
题目1 : String reorder
- 样例输入
-
aabbccdd
007799aabbccddeeff113355zz
1234.89898
abcdefabcdefabcdefaaaaaaaaaaaaaabbbbbbbddddddee - 样例输出
-
abcdabcd
013579abcdefz013579abcdefz
<invalid input string>
abcdefabcdefabcdefabdeabdeabdabdabdabdabaaaaaaa -
用map比较好,这个程序耗时太多,哎。。。
-
代码如下:
Description
For this question, your program is required to process an input string containing only ASCII characters between ‘0’ and ‘9’, or between ‘a’ and ‘z’ (including ‘0’, ‘9’, ‘a’, ‘z’).
Your program should reorder and split all input string characters into multiple segments, and output all segments as one concatenated string. The following requirements should also be met,
1. Characters in each segment should be in strictly increasing order. For ordering, ‘9’ is larger than ‘0’, ‘a’ is larger than ‘9’, and ‘z’ is larger than ‘a’ (basically following ASCII character order).
2. Characters in the second segment must be the same as or a subset of the first segment; and every following segment must be the same as or a subset of its previous segment.
Your program should output string “<invalid input string>” when the input contains any invalid characters (i.e., outside the '0'-'9' and 'a'-'z' range).
Input
Input consists of multiple cases, one case per line. Each case is one string consisting of ASCII characters.
Output
For each case, print exactly one line with the reordered string based on the criteria above.
#include <iostream>
//#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
using namespace std; bool checkstr(string a)
{
for (unsigned int i=0;i<a.size();i++)
{
if (a[i]<'0'||a[i]>'z'||('9'<a[i]&&a[i]<'a'))
{
return false;
}
}
return true;
} int main()
{
string sa;
vector<string> va;
list<char>::iterator it1;
//while(cin>>sa)
while(getline(cin,sa))
{
va.push_back(sa);
}
vector<list<char> > la(va.size()); for (unsigned int i=0;i<va.size();i++)
{
for (unsigned int j=0;j<va[i].size();j++)
{
la[i].push_back(va[i][j]);
}
la[i].sort();
} for (unsigned int i=0;i<va.size();i++)
{
if (checkstr(va[i]))
{
char temp;
it1=la[i].begin();
while (!la[i].empty())
{
cout<<*it1;
temp=*it1;
it1=la[i].erase(it1);
if (it1==la[i].end()&&!la[i].empty())
{
it1=la[i].begin(); }
while(!la[i].empty()&&*it1==temp)
{
++it1;
if (it1==la[i].end()&&!la[i].empty())
{
it1=la[i].begin();
}
}
}
cout<<endl;
}
else
cout<<"<invalid input string>"<<endl;
} //system("pause");
return 0;
}
微软2014实习生及秋令营技术类职位在线测试(题目1 : String reorder)的更多相关文章
- 【微软2014实习生及秋令营技术类职位在线測试】题目2 : K-th string
时间限制:10000ms 单点时限:1000ms 内存限制:256MB Description Consider a string set that each of them consists of ...
- 微软2014实习生招聘笔试第2题 the k-th string
Time Limit: 10000msCase Time Limit: 1000msMemory Limit: 256MB Description Consider a string set that ...
- Luogu 2018 秋令营 Test 2
T1: 题目描述 你正在使用过时的浏览器,洛谷暂不支持. 请 升级浏览器 以获得更好的体验! Bob 来到了一个 $n \times m$ 的网格中,网格里有 $k$ 个豆子,第 $i$ 个豆子位于 ...
- 微软2014校招笔试题-String reorder
Time Limit:10000ms Case Time Limit:1000ms Memory Limit:256MB Description For this question, your pro ...
- 2014-04-09 互联网Web安全职位面试题目汇总
Domain 解释一下同源策略 同源策略,那些东西是同源可以获取到的 如果子域名和顶级域名不同源,在哪里可以设置叫他们同源 如何设置可以跨域请求数据?jsonp是做什么的? Ajax Ajax是否遵循 ...
- 微软在线测试题String reorder
问题描述: Time Limit: 10000msCase Time Limit: 1000msMemory Limit: 256MB DescriptionFor this question, yo ...
- web安全职位面试题目汇总
Domain 解释一下同源策略 同源策略,那些东西是同源可以获取到的 如果子域名和顶级域名不同源,在哪里可以设置叫他们同源 如何设置可以跨域请求数据?jsonp是做什么的? Ajax Ajax是否遵循 ...
- Reduce inversion count 求最小逆序数
本问题出自:微软2014实习生及秋令营技术类职位在线测试 (Microsoft Online Test for Core Technical Positions) Description Find a ...
- String reorder
本问题出自:微软2014实习生及秋令营技术类职位在线测试 (Microsoft Online Test for Core Technical Positions) Description For th ...
随机推荐
- WINDOWS-基础:Thread.Sleep(0)
我们可能经常会用到 Thread.Sleep 函数来使线程挂起一段时间.那么你有没有正确的理解这个函数的用法呢?思考下面这两个问题: 假设现在是 2008-4-7 12:00:00.000,如果我调用 ...
- java,求1-100之和。
package study01; public class TestWhile { public static void main(String[] args) { int sum = 0; int ...
- mysql 定时任务job
mysql 定时任务job 1.通过show EVENTS显示当前定义的事件 2.检查event_scheduler状态:SHOW VARIABLES LIKE 'event_scheduler' 3 ...
- 第四次作业:Windows各种基本应用的命令处理方法
删除文件夹命令? rd (remove directory) 如何给文件夹重新命名? ren (rename) 如何在文件夹中建立文件夹? md swift\a 如何用命令查看文本文件的内容? typ ...
- iOS9适配总结
每年iOS升级,都会带来一些坑,这次iOS9也不例外.本文总结了微信在适配iOS9上遇到的问题和解决方案. 一.iOS9问题汇总 1. 编译问题(Bitcode) 大部分人升级到Xcode7后,首 ...
- dev gridview columns代码管理
进入run designer界面.我们将在代码中设置columns的属性. 类: ViewTriAtt : DevExpress.XtraEditors.XtraUserControl 在类里面设置g ...
- 初涉斯坦纳树&&bzoj4774: 修路
斯坦纳树的基础应用 斯坦纳树有什么用 个人一点粗浅理解…… 最基本形式的斯坦纳树问题(以下简称母问题):给定图G和一个关键点集V.求在G中选取一个权值最小(这里权值可以有很多变式)的边集E使V中的点两 ...
- knn算法之预测数字
训练算法并对算法的准确值准确率进行估计 #导入相应模块 import numpy as npimport pandas as pdimport matplotlib.pyplot as plt%mat ...
- 08/07/2017 R
from today,i will learn something about the R. install R studio code: 1.>install.packages("s ...
- 汇编语言 Part 2——寄存器
处理器操作主要涉及处理数据.这些数据可以存储在内存中并从中访问.但是,读取数据并将其存储到内存中会减慢处理器的速度,因为它涉及将数据请求通过控制总线发送到内存存储单元并通过同一通道获取数据的复杂过程. ...