题目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. mysql+thinkphp +amcharts 完成图表统计功能

    思路:从mysql数据库查询数据,经过thinkphp 后端控制器做逻辑处理,返回给前端,前端调用Amcharts 插件 1.数据查询: public function order($time='', ...

  2. macbook secureCRT终端中文乱码的问题

    最近mac用crt中文总是显示的是一串串问号, 而用自带的终端软件就不会出现乱码, 经过一番折腾暂时解决了这一问题, 方法如下: 1. 打开终端操作 sudo vim /etc/profile 在最后 ...

  3. Maven:项目结构

    目录结构图: project        |- src            |- main   //工程源代码目录                |- java        //工程java源代 ...

  4. iOS与JS相互传值与交互

    JavaScriptCore是webkit的一个重要组成部分,主要是对JS进行解析和提供执行环境.iOS7后苹果在iPhone平台推出,极大的方便了我们对js的操作.我们可以脱离webview直接运行 ...

  5. iOS调用WebService接口

    首先有几点说在前面 一般,在请求URL的后面带有WSDL字样的需要调用WebService URL样式例子:http://ip:port/navigable/webservice/loginSeric ...

  6. iOS监听电话来电、挂断、拨号等

    以下,来讲解在app内如何调用打电话功能和监听电话来电.挂断.拨号等功能. 简单的UI布局: 首先,先实现拨打电话的功能,以便于后续测试: // 拨打电话 - (IBAction)dialingBut ...

  7. Struts2和Spring MVC 区别 今天面试被问到了

    虽然说没有系统的学习过Spring MVC框架, 但是工作这么长时间, 基本上在WEB层使用的都是Spring MVC, 自己觉得Struts2也是一个不错的WEB层框架, 这两种框架至今自己还未有比 ...

  8. python getopt模块使用方法

    python中 getopt 模块,是专门用来处理命令行参数的 getop标准格式: 函数getopt(args, shortopts, longopts = []) shortopts 是短参数   ...

  9. $(MAKE) , make命令

    make 定义了很多默认变量,像常用的命令或者是命令选项之类的,什么CC啊,CFLAGS啊之类.$(MAKE)就是预设的 make 这个命令的名称(或者路径).make -p 可以查看所有预定义的变量 ...

  10. C++中重载、覆盖和隐藏的区别,以及适用场景

    一.重载.覆盖和隐藏的区别 二.适用场景 1.重载: 适用于不同的数据类型都需要使用到的功能函数.以数据相加的函数为例,可以在同一个文件内提供以下的重载函数以支持同样的功能: int add(int, ...