题目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. Spring 和 Mybatis 整合

    Spring 和 Mybatis 整合 Spring本身的Config文件: 在IDEA下面配置好文件后, 在WEB-INF下面有三个配置文件分别是web.xml, applicationContex ...

  2. java中插入myslq的datetime类型的

    java.util.Date d = new java.util.Date(); Timestamp tt=new Timestamp(d.getTime()); ps.setTimestamp(4, ...

  3. CentOS7练习

    为编译安装的httpd服务,实现service unit文件破解centos7 口令修改默认的启动内核为新编译内核启动时临时禁用SELinux启动时进入emergency模式卸载编译安装的新内核

  4. Centos7系统下安装Docker

    1.确定你的Linux系统是Centos7 命令:cat /etc/redhat-release 2.yum安装gcc相关 1.配置好Centos7能上外网. 2.yum -y install gcc ...

  5. Linux菜鸟起飞之路【九】系统启动流程

    Linux系统启动流程 BIOS -> MBR  -> BootLoader -> Kernel -> init 1.打开电源后,计算机从主板的BIOS中读取其中存储的程序.这 ...

  6. vue + axios---封装一个http请求

    在使用vue开发时,官方推荐使用axios来请求接口 // axios官方地址 https://github.com/axios/axios 但是axios并不像 vue-resource 一样拥有i ...

  7. paper:synthesizable finite state machine design techniques using the new systemverilog 3.0 enhancements 之 standard verilog FSM conding styles(二段式)

    1.Two always block style with combinational outputs(Good Style) 对应的代码如下: 2段式总结: (1)the combinational ...

  8. 如何锁定Android系统CPU的频率

    接触到了Android系统的Performance测试,所以有锁定CPU的需求: 由于要首先读取到此系统所支持的CPU频率,之后再所支持的频率中选取你想要的频率,之后进行锁定. 这个过程,手动也是可以 ...

  9. python基础学习笔记——异常处理

    异常处理流程图 一,异常和错误 part1:程序中难免出现错误,而错误分成两种 1.语法错误(这种错误,根本过不了python解释器的语法检测,必须在程序执行前就改正) #语法错误示范一 if #语法 ...

  10. Java-创建一个线程

    第一种继承Thread类 package com.tj; public class BasicThread1 extends Thread { public void run() { System.o ...