题4
来源:互联网 发布:nginx 代理静态页面 编辑:程序博客网 时间:2024/06/05 17:16
import java.util.HashMap;import java.util.Map;import java.util.Scanner;/** * Created by Administrator on 2017/9/22. * 在一个字符串中找到第一个只出现一次的字符。 */public class Main8 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ String s=sc.next(); HashMap<Character,Integer> mapa=new HashMap<>(); HashMap<Character,Integer> mapb=new HashMap<>(); char[] c=s.toCharArray(); for (int i = 0; i <c.length; i++) { if(!mapa.containsKey(c[i])){ mapa.put(c[i],1); }else mapa.put(c[i],mapa.get(c[i])+1); mapb.put(c[i],i); } int index=c.length-1; for(Map.Entry<Character,Integer> e:mapa.entrySet()){ if(e.getValue()==1){ if(index>mapb.get(e.getKey())){ index=mapb.get(e.getKey()); } } } System.out.println(c[index]); } }}
阅读全文
0 0
- 题4
- 题4
- 题4
- 面试100题 题4
- MS100题第4题
- 微软笔试题4
- 面试算法题4
- 经典SQL题4
- 面试模拟题4
- 百度笔试题4
- IBM笔试题4
- 分享Java题4
- 编程趣味题4
- java 笔试题4
- 测试题4
- 笔试题(4)
- 逻辑思维笔试题4
- p27第4题
- 数字再排序数组中出现的次数
- lua基础知识整理
- 计算机启动相关术语、问题
- POJ 3069 Saruman's Army
- 第三周项目三C/C++求集合并集
- 题4
- unity3d ngui 适配性价比最高的方案
- [iOS]Unknown class XXX in Interface Builder file.
- Python 的“保暖裤”
- kafka 创建topic
- 欢迎使用CSDN-markdown编辑器
- PAT甲级解题报告索引
- Python编程——Python基础知识之列表(-)
- [UnityUI]使用UI框架