题目1 : String reorder

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

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.

样例输入
aabbccdd
007799aabbccddeeff113355zz
1234.89898
abcdefabcdefabcdefaaaaaaaaaaaaaabbbbbbbddddddee
样例输出
abcdabcd
013579abcdefz013579abcdefz
<invalid input string>
abcdefabcdefabcdefabdeabdeabdabdabdabdabaaaaaaa
用map比较好,这个程序耗时太多,哎。。。
代码如下:
#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)的更多相关文章

  1. 【微软2014实习生及秋令营技术类职位在线測试】题目2 : K-th string

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB Description Consider a string set that each of them consists of ...

  2. 微软2014实习生招聘笔试第2题 the k-th string

    Time Limit: 10000msCase Time Limit: 1000msMemory Limit: 256MB Description Consider a string set that ...

  3. Luogu 2018 秋令营 Test 2

    T1: 题目描述 你正在使用过时的浏览器,洛谷暂不支持. 请 升级浏览器 以获得更好的体验! Bob 来到了一个 $n \times m$ 的网格中,网格里有 $k$ 个豆子,第 $i$ 个豆子位于 ...

  4. 微软2014校招笔试题-String reorder

    Time Limit:10000ms Case Time Limit:1000ms Memory Limit:256MB Description For this question, your pro ...

  5. 2014-04-09 互联网Web安全职位面试题目汇总

    Domain 解释一下同源策略 同源策略,那些东西是同源可以获取到的 如果子域名和顶级域名不同源,在哪里可以设置叫他们同源 如何设置可以跨域请求数据?jsonp是做什么的? Ajax Ajax是否遵循 ...

  6. 微软在线测试题String reorder

    问题描述: Time Limit: 10000msCase Time Limit: 1000msMemory Limit: 256MB DescriptionFor this question, yo ...

  7. web安全职位面试题目汇总

    Domain 解释一下同源策略 同源策略,那些东西是同源可以获取到的 如果子域名和顶级域名不同源,在哪里可以设置叫他们同源 如何设置可以跨域请求数据?jsonp是做什么的? Ajax Ajax是否遵循 ...

  8. Reduce inversion count 求最小逆序数

    本问题出自:微软2014实习生及秋令营技术类职位在线测试 (Microsoft Online Test for Core Technical Positions) Description Find a ...

  9. String reorder

    本问题出自:微软2014实习生及秋令营技术类职位在线测试 (Microsoft Online Test for Core Technical Positions) Description For th ...

随机推荐

  1. EF6.0注意事项

    EF6 1.必须要添加Entitiframework 2.必须要添加必须要添加Entitiframework.Sqlserver 3.单元测试一定要有配置文件里面一定要有连接字符串和初始化配置文件节点 ...

  2. HDU 5090 Game with Pearls (贪心)

    一道贪心的题,因为最小的不能由别的转化,所以每次贪心找最小的,其余的转化成大的. 从小到大,最小的如果不存在那么就break,否则减去一个,剩下的加k继续判断. #include<cstdio& ...

  3. UVA 12325 Zombie'sTreasureChest 宝箱 (分类枚举)

    看上去非常像背包的问题,但是体积太大了. 线性规划的知识,枚举附近点就行了,优先选性价比高的, 宝物有两种体积为S0,价值V0,体积S1,价值V1. 枚举分以下几种: 1:枚举拿宝物1的数量,然后尽量 ...

  4. python_100_静态方法

    class Dog(object): def __init__(self,name): self.name=name @staticmethod#实际上跟类没什么关系了 def eat():#def ...

  5. Dojo的ready函数:dojo.ready(以前的dojo.addOnLoad)

    dojo的dojo/domReady!插件和dojo/ready的区别:     In simple cases,dojo/domReady! should be used. If an app us ...

  6. 不安装oracle客户端如何使用plsql连接数据库

    不安装oracle客户端如何使用plsql连接数据库 1. 准备工作 1.1下载plsqldev破解版软件 我这里使用plsqldev715版本 1.2下载instantclient-basic-wi ...

  7. pandas处理大文本数据

    当数据文件是百万级数据时,设置chunksize来分批次处理数据 案例:美国总统竞选时的数据分析 读取数据 import numpy as np import pandas as pdfrom pan ...

  8. 04 Django模板

    基本概念 作为Web框架,Django提供了模板,用于编写html代码,还可以嵌入模板代码更快更方便的完成页面开发,再通过在视图中渲染模板,将生成最终的html字符串返回给客户端浏览器 模版致力于表达 ...

  9. graph-SCC

    strongly connected component(SCC): 里面的任一对顶点都是互相可达的. 一个有向图,将每个SCC缩成一个点,那么这个图就变成了DAG(有向无环图). 原图进行DFS之后 ...

  10. LeetCode(306) Additive Number

    题目 Additive number is a string whose digits can form additive sequence. A valid additive sequence sh ...