华为2017校招第二题删除重复的数,得到最大值。
来源:互联网 发布:php7不支持mysql扩展 编辑:程序博客网 时间:2024/06/05 02:01
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#include <string>
#include <cstring>
int main(){
string str;
int a[128];
while(cin>>str){
memset(a,0,sizeof(a));
int len=str.size();
for(int i=0;i<len;i++){
a[str[i]]++;
}
for(int i=0;i<str.length();i++){
for(int j=i;j<str.length();j++){
if(str[i]<str[j]&&a[str[i]]>1)
{
a[str[i]]--;
str.erase(i,1);
}
else if(str[i]==str[j]&&i!=j){
a[str[j]]--;
str.erase(j,1);
}
}
// for(int i=0;i<str.length();i++)
// cout<<i<<" "<<a[str[i]]<<endl;
}
// for(int i=0;i<str.length();i++)
// cout<<i<<" "<<a[str[i]]<<endl;
// cout<<str.length();
cout<<str<<endl;
}
}
阅读全文
0 0
- 华为2017校招第二题删除重复的数,得到最大值。
- 华为2018校招第二题 求去重后的最大整数
- 华为模拟题第二题--Google校招笔试题
- C#得到三个数的最大值
- 2017华为校招编程题2
- 实现返回大于A的最小“不重复数” 百度2014校招笔试题
- 华为校招上机题
- 校招第二站-----爱数
- 华为:查找最大的不重复数
- 华为OJ 提出不重复的数
- 删除链表中重复的数
- 输入三个数,得到最大值
- 2014华为校招 重邮机试 2013.9.14 第二场
- 华为2018秋招编程题1:在字符串中找出连续最长的数字串
- 华为2017校招C++岗笔试题
- 第二个重复出现的数
- 2017华为校招硬件逻辑工程师
- 2017华为暑期实习生校招笔试
- 通过xhell输入命令对多个linux进行同时操作
- hdu 6108 小C的倍数问题【一个数的因子个数】
- C#中this的用法
- 读写CFILE 与UpdateData
- Hibernate之HQL的基本用法
- 华为2017校招第二题删除重复的数,得到最大值。
- 【模板】缩点 洛谷p3387
- 2017.8.23考试
- php 微信开发回复消息
- 【清华集训2017模拟】Create
- Codeforces 785B Anton and Classes(贪心)
- bootstrap angularjs 实现jsp页面购物车
- 剑指Offer—28—数组中出现次数超过一半的数字
- 润乾报表如何配置/部署多个lmd文件