当前位置:网站首页>字符集合(去重)
字符集合(去重)
2022-04-22 23:43:00 【月半的人】
输入一个字符串,求出该字符串包含的字符集合,按照字母输入的顺序输出。
数据范围:输入的字符串长度满足 1≤n≤100 1 \le n \le 100 \ 1≤n≤100 ,且只包含大小写字母,区分大小写。
本题有多组输入
输入:
每组数据输入一个字符串,字符串最大长度为100,且只包含字母,不可能为空串,区分大小写。
输出:
每组数据一行,按字符串原有的字符顺序,输出字符集合,即重复出现并靠后的字母不输出。
首先这个题的输入的是只有字母的大小写的字母组成的字符串。按顺序输出不重复的元素。
做题思想:
首先,我们的的每个字母都有相对于的int类型的数组。我们只要遍历这个字符串,找到每个字符所得值,在同时,如果这个字符所对应的数组的值是0那么就代表没有重复,那么就将这个字符加到另外一个引用变量,然后再讲这个字符对应的数组的值++,这样如果后面有重复的字母,每次会找到这个数组,发现不是0,那么就不会再将其加入到string引用中。这样我们就可以解题了。
import java.util.Scanner;
public class Main {
public static StringBuilder func(String str){
int[] ch = new int[257];
StringBuilder set = new StringBuilder("");
int tem;
for(int i = 0;i<str.length();i++){
tem = str.charAt(i);
if(ch[tem]==0){
set.append(str.charAt(i));
ch[tem]++;
}
}
return set;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
StringBuilder set = func(str);
System.out.println(set.toString());
}
}
链接:字符集合__牛客网
来源:牛客网
版权声明
本文为[月半的人]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_61652218/article/details/124327758
边栏推荐
- 2022-04-22:给你一个大小为 m x n 的矩阵 board 表示甲板,其中,每个单元格可以是一艘战舰 ‘X‘ 或者是一个空位 ‘.‘ ,返回在甲板 board 上放置的 战舰 的数量。 战舰
- [leetcode] binary tree, in-depth understanding of the first, middle and last order
- Beijing University of Aeronautics and Astronautics launched the trial of cnopendata
- 漏洞利用与安全加固
- Want others to watch your video? Comment on your video? It's enough to learn these two moves
- 分享两道最近做的比较经典的OJ题(排列子序列+字符串中找出连续最长的数字串)
- 【DVCon2020】基于RAL的UVM Sequence自动生成方法
- Design of optical fingerprint module unlocking scheme fingerprint lock scheme
- 一个关于混淆的 Native 崩溃分析
- [leetcode refers to offer 54. The k-th node of the binary search tree (simple)]
猜你喜欢

简便工作时间的法宝:以密钥验证的方式来登录服务器

On LD_ Preload hijacking
![[dvcon2020] acceleration of low power design level verification based on signoff abstract model](/img/c1/3495627bf41f5ba8b06d624831e6d8.png)
[dvcon2020] acceleration of low power design level verification based on signoff abstract model
![[pyGame] can the little dinosaur on chrome be played with code? It looks like fun~](/img/b4/a4140eb10658af40a8a2fc0f428b0f.jpg)
[pyGame] can the little dinosaur on chrome be played with code? It looks like fun~
![[leetcode] binary tree, maximum depth of 104 binary tree, diameter of 543 binary tree, maximum path and sum of 124 binary tree](/img/f8/5de0ecee78a6f9c9bd8562629355be.png)
[leetcode] binary tree, maximum depth of 104 binary tree, diameter of 543 binary tree, maximum path and sum of 124 binary tree

Cause analysis of SQL net message from client event

visual studio 2019恢复默认设置

A native crash analysis of confusion
![FileNotFoundError: [Errno 2] No such file or directory: 'image/1.jpg'问题解决](/img/dd/d8068792911be2d04a04eb4c1a158c.png)
FileNotFoundError: [Errno 2] No such file or directory: 'image/1.jpg'问题解决
![FileNotFoundError: [Errno 2] No such file or directory: 'image/1. Jpg 'problem solving](/img/72/dca1064713646f909c4a7a8567a742.png)
FileNotFoundError: [Errno 2] No such file or directory: 'image/1. Jpg 'problem solving
随机推荐
LabVIEW controls computer shutdown, hibernation, logout and restart
[note] PCIe ltssm status transition
【Pygame小游戏】Chrome上的小恐龙竟可以用代码玩儿了?它看起来很好玩儿的样子~
Common search engines and syntax
[PCIe 6.0] new features of PCIe 6.0 - detailed explanation of dmwr (deferred memory write)
Read software engineering at Google (12)
JUC 全套(1)
51 单片机学习_4-1 数码管显示
2面技术 HR面 offer,系列篇
MPP架构概念
Thread pool (easy to understand)
[perseverance challenge] PCIe asks and answers every day (filed on March 2022)
【leetcode】二叉树,深入理解前中后序
2022硬刚PLUS德施曼年度峰会:多款领航旗舰发布,引领高端市场
MPP architecture concept
[leetcode refers to the path with a certain value in offer 34. Binary tree (medium)]
[turtle confession collection] "the moon at the bottom of the sea is the moon in the sky, and the person in front of us is the sweetheart." More joy and peace for the rest of your life ~ (with 3 sourc
VsCode使用EmmyLua插件调试Unity工程ToLua代码
共轭梯度法(Conjugate Gradients)(3)
Hello, I want to open an account for crude oil futures. How can I open an account for futures safely and reliably?