微软实习生测试题题目1 : String reorder

2024-05-26 01:08

本文主要是介绍微软实习生测试题题目1 : String reorder,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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 consists of multiple cases, one case per line. Each case is one string consisting of ASCII characters.

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
代码:
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;bool parseChar(char * c);class CInputStr
{
public:char m_cStr;int m_iNum;
};
struct Cmp_by_name   //为排序编写的结构体
{bool operator()(const CInputStr &a, const CInputStr &b){return a.m_cStr<b.m_cStr;}
};
int main() {char c[5][100];  char * result[5];int inumcount;  int index=0;  int temp;  int minnum=10000;for (int i=0;i<5;i++){cin.getline(c[i],100);if (parseChar(c[i])){}else{char b[100]="<invalid input string>";strcpy(c[i],b);}}for (int i=0;i<5;i++){cout<<c[i]<<endl;}
}
bool parseChar(char * c)
{int icount=0;char * result=c;vector <CInputStr> vInput;while(c[icount]!='\0'){if ((c[icount]>='0'&&c[icount]<='9')||(c[icount]>='a'&&c[icount]<='z')){if (0==vInput.size()){CInputStr cinput;cinput.m_cStr=c[icount];cinput.m_iNum=1;vInput.push_back(cinput);}else{for (int i=0;i<vInput.size();i++){if (c[icount]==vInput[i].m_cStr){vInput[i].m_iNum++;break;}if (i==vInput.size()-1){CInputStr cinput;cinput.m_cStr=c[icount];cinput.m_iNum=1;vInput.push_back(cinput);break;}}}}else{return false;}icount++;}int iVectorCount=0;icount=0;sort(vInput.begin(),vInput.end(),Cmp_by_name());while (0!=vInput.size()){if (0!=vInput[iVectorCount].m_iNum){result[icount]=vInput[iVectorCount].m_cStr;vInput[iVectorCount].m_iNum-=1;icount++;}else{if(0==vInput[vInput.size()-1].m_iNum){vInput.pop_back();}}if (iVectorCount+1>=vInput.size()){iVectorCount=0;}else{iVectorCount++;}}vInput.empty();return true;
}


这篇关于微软实习生测试题题目1 : String reorder的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1003127

相关文章

题目1254:N皇后问题

题目1254:N皇后问题 时间限制:1 秒 内存限制:128 兆 特殊判题:否 题目描述: N皇后问题,即在N*N的方格棋盘内放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在同一斜线上。因为皇后可以直走,横走和斜走如下图)。 你的任务是,对于给定的N,求出有多少种合法的放置方法。输出N皇后问题所有不同的摆放情况个数。 输入

题目1380:lucky number

题目1380:lucky number 时间限制:3 秒 内存限制:3 兆 特殊判题:否 提交:2839 解决:300 题目描述: 每个人有自己的lucky number,小A也一样。不过他的lucky number定义不一样。他认为一个序列中某些数出现的次数为n的话,都是他的lucky number。但是,现在这个序列很大,他无法快速找到所有lucky number。既然

微软正式推出 Spartan 斯巴达浏览器

作为用于替代 IE 浏览器的下一代继任者,微软的 Project Spartan 斯巴达浏览器可算是吊足了玩家们的胃口!如今,在最新的 Windows 10 Build 10049 版本起,它终于正式登场了。 斯巴达浏览器搭载了全新的渲染引擎、新的用户界面并集成了 Cortana 语音助手。功能上新增了稍后阅读列表、阅读视图、F12开发者工具、支持网页注释 (手写涂鸦),可以保存到 O

【408数据结构】散列 (哈希)知识点集合复习考点题目

苏泽  “弃工从研”的路上很孤独,于是我记下了些许笔记相伴,希望能够帮助到大家    知识点 1. 散列查找 散列查找是一种高效的查找方法,它通过散列函数将关键字映射到数组的一个位置,从而实现快速查找。这种方法的时间复杂度平均为(

string字符会调用new分配堆内存吗

gcc的string默认大小是32个字节,字符串小于等于15直接保存在栈上,超过之后才会使用new分配。

码蹄集部分题目(2024OJ赛9.4-9.8;线段树+树状数组)

1🐋🐋配对最小值(王者;树状数组) 时间限制:1秒 占用内存:64M 🐟题目思路 MT3065 配对最小值_哔哩哔哩_bilibili 🐟代码 #include<bits/stdc++.h> using namespace std;const int N=1e5+7;int a[N],b[N],c[N],n,q;struct QUERY{int l,r,id;}que

2024 年高教社杯全国大学生数学建模竞赛题目——2024 年高教社杯全国大学生数学建模竞赛题目的求解

2024 年高教社杯全国大学生数学建模竞赛题目 (请先阅读“ 全国大学生数学建模竞赛论文格式规范 ”) 2024 年高教社杯全国大学生数学建模竞赛题目 随着城市化进程的加快、机动车的快速普及, 以及人们活动范围的不断扩大,城市道 路交通拥堵问题日渐严重,即使在一些非中心城市,道路交通拥堵问题也成为影响地方经 济发展和百姓幸福感的一个“痛点”,是相关部门的棘手难题之一。 考虑一个拥有知名景区

力扣 739. 每日温度【经典单调栈题目】

1. 题目 理解题意: 1.1. 给一个温度集合, 要返回一个对应长度的结果集合, 这个结果集合里面的元素 i 是 当前 i 位置的元素的下一个更高温度的元素的位置和当前 i 位置的距离之差, 若是当前元素不存在下一个更高温度的元素, 则这个位置用0代替; 2. 思路 本题用单调栈来求解;单调栈就适用于来求当前元素左边或者右边第一个比当前元素大或者小的元素;【单调栈:让栈中的元素保持单调

msyql执行效率的问题以及常见基础面试题目

SQL被称为结构化查询语言(Structured Query Language )是操作和检索关系型数据库的标准语言 SQL语言包括三种主要程序设计语言类别的语句:数据定义语言(DDL),数据操作语言(DML)及数据控制语言(DCL)。 ※ 数据定义语言(DDL),例如:CREATE、DROP、ALTER等语句。    Data Definition Language ※ 数据