当前位置:网站首页>Character set (de duplication)
Character set (de duplication)
2022-04-22 23:50:00 【A man of half a month】
Enter a string , Find the character set contained in the string , Output in alphabetical order .
Data range : The length of the input string meets the requirements 1≤n≤100 1 \le n \le 100 \ 1≤n≤100 , And contains only uppercase and lowercase letters , Case sensitive .
There are many groups of input
Input :
Enter a string for each group of data , The maximum length of the string is 100, And contains only letters , It can't be an empty string , Case sensitive .
Output :
One line for each group of data , In the original character order of the string , Output character set , That is, the repeated and subsequent letters are not output .
First of all, the input of this question is a string composed of upper and lower case letters with only letters . Output non repeating elements in order .
Topic idea :
First , Each of our letters has a relative int An array of types . We just need to traverse this string , Find the value of each character , At the same time , If the value of the array corresponding to this character is 0 Then it means there is no repetition , Then add this character to another reference variable , Then we'll talk about the value of the array corresponding to this character ++, So if there's a duplicate letter after it , Every time I find this array , The discovery is not 0, Then it won't be added to string In the reference . So we can solve the problem .
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());
}
}
link : Character set __ Cattle from
source : Cattle from
版权声明
本文为[A man of half a month]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204222343285809.html
边栏推荐
- 【超能力】我想暂停时空
- [leetcode] binary tree, maximum depth of 104 binary tree, diameter of 543 binary tree, maximum path and sum of 124 binary tree
- 《新程序员003》正式上市,华为、阿里等 30+ 公司的云原生及数字化实战经验
- Conjugate gradients (3)
- Typora style tuning
- ssh: connect to host 172.31.8.132 port 22: Connection refused
- [PCIe 6.0] new features of PCIe 6.0 - detailed explanation of dmwr (deferred memory write)
- Django connects to the database to obtain data
- visual studio 2019恢复默认设置
- The parameter configuration of websoket package is out of the box
猜你喜欢

MySQL索引的语法是什么

【年度总结】继往开来:回首不靠谱的2021,希冀靠谱的2022
![[dvcon2020] simulation acceleration method based on multithreaded UVM test platform](/img/84/71895a669fef22b172183ae805427d.png)
[dvcon2020] simulation acceleration method based on multithreaded UVM test platform

matlab-day01
![[PCIe 6.0] new features of PCIe 6.0 - detailed explanation of l0p](/img/2a/41a4d80e2ea729b01268c856504a84.png)
[PCIe 6.0] new features of PCIe 6.0 - detailed explanation of l0p

2022-04-22: give you a matrix board with the size of m x n to represent the deck, where each cell can be a warship 'x' or an empty space ', Returns the number of warships placed on the deck board. war

LabVIEW implements application stop or exit

【毅力挑战】PCIe 每日一问一答(2022.02 归档)

【DVCon2020】采用先进 Save & Restore 技术加速仿真周转时间 (Simulation Turnaround Time)

【Turtle表白合集】“海底月是天上月,眼前人是心上人。”余生多喜乐,长平安~(附3款源码)
随机推荐
[perseverance challenge] PCIe asks and answers every day (2022.04 in progress)
Write a Tetris game in C language
居家第二十二天的绿豆芽
[newcoder] week 20220422
IOT identity awareness
Django指定数据库的时候报No module named ‘django_test.settings‘
[dvcon2020] software brothers shout: Hardware brothers, please be personal
Financial information security training -- 22 / 4 / 19 (Part 2)
Common search engines and syntax
[Objective-C advanced programming] - GCD
Django connects to the database to obtain data
【毅力挑战】PCIe 每日一问一答(2022.04 进行中)
【leetcode】二叉树,深入理解前中后序
人们对于产业互联网的认识越来越清晰,越来越接近产业互联网
unbuntu18. 04 installing gamit10 71 problem solution
共轭梯度法(Conjugate Gradients)(3)
【newcoder】20220422周赛
xpath定位
[leetcode] binary tree, 654 largest binary tree, 105 constructs binary tree according to preorder and inorder traversal, 106 constructs binary tree according to inorder and postorder traversal, and 88
FileNotFoundError: [Errno 2] No such file or directory: 'image/1.jpg'问题解决