check Str's Character appearence frequence is ge 1
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ; import java.util.*; public class HackerRankTest { public static void main(String[] args) {
String srcStr="We promptly judged antique ivory buckles for the next prize";
String srcStr1="We promptly judged antique ivory buckles for the prize";
boolean checkStrIsSubStr = checkStrIsSubStr(srcStr);
if (checkStrIsSubStr){
System.out.println("pangram");
}else {
System.out.println("not pangram");
} boolean checkStrIsSubStr1 = checkStrIsSubStr(srcStr1);
if (checkStrIsSubStr1){
System.out.println("pangram");
}else {
System.out.println("not pangram");
}
} /**
* judge Str's Character appearence frequence is ge 1.
* @param srcStr
* @return
*/
public static boolean checkStrIsSubStr(String srcStr){
if (srcStr==null){
return false;
}
if (srcStr.isEmpty()){
return false;
}
int length = srcStr.length();
if (length<1 || length>1000){
return false;
}
for (int i = 0; i < length; i++) {
char charAt = srcStr.charAt(i);
if (charAt==' '){
continue;
}else if (charAt>='A' && charAt<= 'z'){
continue;
}else {
return false;
}
} HashMap<Character, Integer> characterIntegerHashMap = new HashMap<Character, Integer>();
String srcStrDest = srcStr.replaceAll("\\s", "&");
for (int i = 0; i < length; i++) {
char charAt = srcStrDest.charAt(i);
if (characterIntegerHashMap.containsKey(charAt)){
characterIntegerHashMap.put(charAt,characterIntegerHashMap.get(charAt)+1);
}else {
characterIntegerHashMap.put(charAt,1);
}
} ArrayList<CustomerCharacterRec> customerCharacterRecArrayList = new ArrayList<CustomerCharacterRec>(); for (Map.Entry<Character,Integer> entry: characterIntegerHashMap.entrySet()) {
Character key = entry.getKey();
Integer entryValue = entry.getValue(); CustomerCharacterRec customerCharacterRec = new CustomerCharacterRec();
UUID randomUUID = UUID.randomUUID();
String toString = randomUUID.toString();
customerCharacterRec.setId(toString);
customerCharacterRec.setSrcCharacter(key);
customerCharacterRec.setCountFrequence(entryValue); customerCharacterRecArrayList.add(customerCharacterRec); } System.out.println(customerCharacterRecArrayList); String srcStrStr=" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
HashMap<Character, Integer> characterIntegerHashMap1Src = new HashMap<Character, Integer>();
for (int i = 0; i < srcStrStr.length(); i++) {
char charAt = srcStrStr.charAt(i);
if (charAt==' '){
charAt='&';
}
characterIntegerHashMap1Src.put(charAt,1);
} ArrayList<CustomerCharacterRec> customerCharacterRecs1SrcList = new ArrayList<CustomerCharacterRec>();
for (Map.Entry<Character,Integer> entry : characterIntegerHashMap1Src.entrySet()) {
Character key = entry.getKey();
Integer entryValue = entry.getValue(); CustomerCharacterRec customerCharacterRecSrc = new CustomerCharacterRec();
UUID randomUUID = UUID.randomUUID();
String toString = randomUUID.toString();
customerCharacterRecSrc.setId(toString); customerCharacterRecSrc.setSrcCharacter(key);
customerCharacterRecSrc.setCountFrequence(entryValue); customerCharacterRecs1SrcList.add(customerCharacterRecSrc);
} System.out.println("---------srcDataSet------");
// System.out.println(customerCharacterRecs1SrcList); Collections.sort(customerCharacterRecs1SrcList,new Comparator<CustomerCharacterRec>() {
@Override
public int compare(CustomerCharacterRec o1, CustomerCharacterRec o2) {
if (o1.getSrcCharacter()>o2.getSrcCharacter()){
return 1;
}else if(o1.getSrcCharacter()<o2.getSrcCharacter()){
return -1;
}
return 0;
}
}); System.out.println(customerCharacterRecs1SrcList); Collections.sort(customerCharacterRecArrayList, new Comparator<CustomerCharacterRec>() {
@Override
public int compare(CustomerCharacterRec o1, CustomerCharacterRec o2) {
if (o1.getSrcCharacter()>o2.getSrcCharacter()){
return 1;
}else if (o1.getSrcCharacter()<o2.getSrcCharacter()){
return -1;
}
return 0;
}
}); System.out.println(customerCharacterRecArrayList); for (CustomerCharacterRec customerCharacterRec : customerCharacterRecs1SrcList) {
Character srcCharacter = customerCharacterRec.getSrcCharacter();
Integer countFrequence = customerCharacterRec.getCountFrequence(); for (CustomerCharacterRec characterRec : customerCharacterRecArrayList) {
Character srcCharacter1 = characterRec.getSrcCharacter();
Integer countFrequence1 = characterRec.getCountFrequence(); if (srcCharacter==srcCharacter1){
if (countFrequence1>=countFrequence){
return true;
}else {
return false;
}
}
}
} return false;
} } class CustomerCharacterRec{
private String id;
private Character srcCharacter;
private Integer countFrequence; public String getId() {
return id;
} public void setId(String id) {
this.id = id;
} public Character getSrcCharacter() {
return srcCharacter;
} public void setSrcCharacter(Character srcCharacter) {
this.srcCharacter = srcCharacter;
} public Integer getCountFrequence() {
return countFrequence;
} public void setCountFrequence(Integer countFrequence) {
this.countFrequence = countFrequence;
} @Override
public String toString() {
return "CustomerCharacterRec{" +
"id='" + id + '\'' +
", srcCharacter=" + srcCharacter +
", countFrequence=" + countFrequence +
'}';
}
}
check Str's Character appearence frequence is ge 1的更多相关文章
- check windows return character
#ifndef _FILE_CHECK_H#define _FILE_CHECK_H#include <string.h>#include <vector> const int ...
- python之Character string
1.python字符串 字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串,l Python不支持单字符类型,单字符也在Python也是作为一个字符串使用. ...
- python基础===Character string
本文转自:python之Character string 1.python字符串 字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串,l Python不支持单 ...
- 【Python】python之Character string
1.python字符串 字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串,l Python不支持单字符类型,单字符也在Python也是作为一个字符串使用. ...
- Leetcode分类刷题答案&心得
Array 448.找出数组中所有消失的数 要求:整型数组取值为 1 ≤ a[i] ≤ n,n是数组大小,一些元素重复出现,找出[1,n]中没出现的数,实现时时间复杂度为O(n),并不占额外空间 思路 ...
- Java集合框架练习-计算表达式的值
最近在看<算法>这本书,正好看到一个计算表达式的问题,于是就打算写一下,也正好熟悉一下Java集合框架的使用,大致测试了一下,没啥问题. import java.util.*; /* * ...
- POJ2955:Brackets(区间DP)
Description We give the following inductive definition of a “regular brackets” sequence: the empty s ...
- Angular源代码学习笔记-原创
时间:2014年12月15日 14:15:10 /** * @license AngularJS v1.3.0-beta.15 * (c) 2010-2014 Google, Inc. http:// ...
- 【转】double-array trie 译文+心得
原文:http://blog.csdn.net/zzran/article/details/8462002 概论 下面将呈现一种新的内部数组结构,它便是double-array.double-arra ...
- 201521123070 《JAVA程序设计》第7周学习总结
1. 本章学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 2. 书面作业 Q1. ArrayList代码分析 1.1 解释ArrayList的contains源代码 源代码: pub ...
随机推荐
- 【经验分享】全志科技官方Ubuntu16.04根文件系统镜像的替换和测试方法
本文主要基于全志A40i开发板--TLA40i-EVM,一款基于全志科技A40i处理器设计的4核ARM Cortex-A7高性能低功耗国产评估板,演示Ubuntu根文件系统镜像的替换和测试方法. 创 ...
- SqlCel 和MySQL for Excel在批量处理数据上的优劣
先放MySQL for Excel编辑数据的界面, 理论上可以批量修改数据....但是: 百度翻译如下: 更改不被允许.....[经测试,64位的Excel出现同样的情况] 转换思路:不使用公式去匹配 ...
- Nginx负载配置
目录 Nginx 负载均衡笔记 1. 概述 1.1 Nginx 简介 1.2 负载均衡概述 2. 四层负载均衡(传输层) 2.1 工作原理 2.2 特点 2.3 优缺点 优点 缺点 2.4 示例场景 ...
- mac idea 更换主题
使用 主题一 xcode-dark-theme:点我直达 主题二 one-dark-theme:点我直达 主题三 dark-purple-theme:点我直达 主题四(推荐) vuesion-them ...
- yb课堂之分布式应用下登陆校验解决方案 JWT讲解 json wen token 《八》
什么是JWT? JWT是一个开放标准,它定义了一种用户简介,自包涵的用于通信双方之间以JSON对象的形式安全传递信息的方法.可以使用HMAC算法或者是RSA的公钥密钥进行签名 简单来说:就是通过一定规 ...
- LSTM实现文本情感分类demo
import torch import torch.optim as optim import torch.nn as nn import numpy as np import torch.nn.fu ...
- 一套基于 Ant Design 和 Blazor 的开源企业级组件库
前言 今天大姚给大家分享一套基于Ant Design和Blazor的开源(MIT License).免费的企业级组件库(喜欢Ant Design风格的同学推荐使用):Ant Design Blazor ...
- MDI子窗口+事件与委托的一个例程
1首先,新建WinForm的.NetFramWork的工程并添加2个Form: 2设置 Form1为MDI主窗口: [属性]-- 将以上属性改为 True; 另外,也可以采用代码形式: this.Is ...
- vue小知识~使用$attrs和$listeners接收父组件转来的属性和方法
一般下我们子组件获取父组件传过来的的值得时候,我们是使用props来接收,但是如果我们父组件转过来的值是给孙组件使用时,使用哪个props接收的方式太过麻烦. 这是vue为我们提供了一个实例$attr ...
- ABC358
A link -- 点击查看代码 #include<bits/stdc++.h> using namespace std; string s,t; signed main(){ cin & ...