java对字符串归一化_字符串归一化
5
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
char[] chars=sc.nextLine().toCharArray();
//经验,一般是用hashmap来统计出现次数的,
//但本题是对字符统计次数,可以专门用一个counts数组来统计次数
int[] counts=new int[26];
for(int i=0;i
counts[chars[i]-'a']++;
}
for(int i=0;i<26;i++){
char c=(char)('a'+i);
int count=counts[i];
if(count==0){
continue;
}else{
System.out.print(c+""+count);
}
}
}
}
发表于 2019-08-05 21:59:53
回复(0)
4
string = input()
for i in sorted(list(set(string))):
item = string.count(i)
print(i + str(item), end = '')
发表于 2019-10-10 22:00:53
回复(2)
3
#include
using namespace std;
int main()
{
string s;
while(cin>>s)
{
sort(s.begin(),s.end());
string res="";
int n=1;
cout<
for(int i=1;i
{
if(s[i]==s[i-1])
n++;
else
{
cout<
cout<
n=1;
}
}
cout<
}
return 0;
}
发表于 2019-06-30 18:55:06
回复(0)
2
#include
#include
using namespace std;
int main(){
int count[26] = {0}; //记录每个字母的个数
string s;
cin >> s;
for(int i = 0; i
count[s[i]-'a']++;
}
char c = 'a';
for(int i = 0; i
if(count[i]){
cout <
}
c++;
}
cout <
return 0;
}
发表于 2019-09-03 23:03:31
回复(0)
3
#include
using namespace std;
int main(){
string s;
while(cin>>s){
int l = s.length();
int cnt[26] = {0};
for(int i=0;i
cnt[s[i]-'a']++;
for(int i=0;i<26;i++){
if(cnt[i]>=1)
cout<
}
cout<
}
return 0;
}
发表于 2019-07-07 22:55:35
回复(0)
1
#include
#include
#include
#include
using namespace std;
int main(){
char ch;
map m;
while(cin>>ch){
m[ch]++;
}
map::iterator it;
for(it=m.begin();it!=m.end();it++){
cout<first<second;
}cout<
return 0;
}
编辑于 2020-04-13 14:46:28
回复(0)
1
Java解法
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] count = new int[256];
String s = scanner.nextLine();
char[] array = s.toCharArray();
for (char c : array) {
count[c]++;
}
StringBuilder builder = new StringBuilder();
for (int i = 'a'; i <= 'z'; i++) {
if (count[i]!=0){
builder.append((char)i);
if (count[i]!=1)
builder.append(count[i]);
}
}
System.out.println(builder.toString());
}
}
发表于 2020-03-01 20:03:35
回复(0)
1
#include
using namespace std;
const int SIZE = 128;
int main()
{
int num[26] = {0}; //26个字母
char buf[SIZE]; //定义输入字符的buf大小
fgets(buf,SIZE,stdin); //键盘输入
int i = 0;
while(buf[i]!='\n') //循环检测相同的字母
{
++num[buf[i++]-'a']; //检测到相同的字母,++操作
if(i==SIZE) // 考虑输入太多的字母的条件
{
i = 0;
fgets(buf,SIZE,stdin);
}
}
i = 0;
while(i<26) //循环输出
{
if(num[i]!=0) //判断字母存在不,没有则不用输入
{
//printf("%c%d",i+'a',num[i]);
char p;
p = i+'a'; //按照字符的顺序输出
cout<
}
++i;
}
cout<
return 0;
}
发表于 2019-10-09 17:30:40
回复(0)
1
#include
#include
using namespace std;
int main()
{ int a[26] = { 0 }; string str; cin >> str; for (int i = 0; i < str.size(); i++) { a[str[i] - 'a']++; }
char ch = 'a';
for(int j = 0;j<26;j++)
{
if(a[j])
cout << ch << a[j];
ch++;
} return 0;
}
编辑于 2019-10-07 21:34:59
回复(0)
1
#include
#include
#include
using namespace std;
int main(){
string s;
getline(cin,s);
map m;//map自动排序
for(int i=0;i
m[s[i]]++;
}
auto it=m.begin();
while(it!=m.end()){
cout<first<second;
it++;
}
return 0;
}
发表于 2019-08-23 20:02:20
回复(2)
1
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Solution6_字符串归一化 {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String str = bf.readLine();
//存储每个字母出现的次数,0~a,1~b
int[] nums = new int[26];
for (int i = 0; i < str.length(); i++) {
nums[str.charAt(i) - 'a']++;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 26; i++) {
if (nums[i] > 0) sb.append((char) (i + 'a')).append(nums[i]);
}
System.out.println(sb.toString());
}
}
发表于 2019-08-03 19:57:30
回复(0)
1
"""
使用Counter计数器
"""
import sys
import collections
if __name__ == "__main__":
# sys.stdin = open("input.txt", "r")
s = input().strip()
obj = collections.Counter(s)
d = sorted(obj.items(), key=lambda c: c[0])
ans = ""
for i in range(len(d)):
ans += str(d[i][0]) + str(d[i][1])
print(ans)
发表于 2019-07-06 21:25:13
回复(0)
1
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String str = sc.nextLine();
int [] array=new int [26];
for (int i = 0; i < str.length(); i++)
array[str.charAt(i)-'a']++;
for (int i = 0; i < 26; i++)
{
if(array[i]>=1)
System.out.print((char)('a'+i));
if(array[i]>1)
System.out.print(array[i]);
}
}
}
编辑于 2019-07-11 17:00:37
回复(0)
1
fromcollections importCounter
s =input()
c =Counter(s)
ans =''
fork insorted(c.keys()):
ans +=k
ans +=str(c[k])
print(ans)
发表于 2019-03-30 14:30:40
回复(1)
1
n = input()
n_dict = {}
for i in n:
if i not in n_dict: # 若dict中不包含此元素
n_dict.update({i: 1}) # 将元素以 {元素:出现次数} 的格式,添加到dict中
else:
n_dict[i] += 1 # 若存在元素,则将对应元素的出现次数+1
# 格式化输出
res_list = []
for i in n_dict:
res_list.append(str(i) + str(n_dict[i]))
res_list.sort()
for i in res_list:
print(i, end='') # 输出不换行
发表于 2019-09-20 15:52:28
回复(0)
0
//TreeMap存储
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
String str = scan.nextLine();
StringBuilder result = new StringBuilder();
TreeMap map = new TreeMap<>();
for(char ch : str.toCharArray()){
if(map.containsKey(ch)){
int count = map.get(ch);
map.put(ch,++count);
}else{
map.put(ch,1);
}
}
for(Map.Entry entry : map.entrySet()){
result.append(entry.getKey());
result.append(entry.getValue());
}
System.out.print(result);
}
}
}
发表于 2020-08-15 15:15:58
回复(0)
0
import sys
messages = sys.stdin.readline().strip().split()
in_str = messages[0]
res = {}
for i in set(in_str):
res[i] = in_str.count(i)
final_str = ''
final_res = sorted(res.items(),key = lambda x:x[0])
for k,v in final_res:
final_str+=k
final_str+=str(v)
print(final_str)
发表于 2020-06-09 11:41:42
回复(0)
0
import java.util.*;
public class Test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
char[] chars = scanner.next().toCharArray();
int[] counts = new int[26];
for (int i=0; i
counts[chars[i] - 'a'] ++;
}
for (int j=0; j
char c = (char) (j + 'a');
int count = counts[j];
if (count != 0){
System.out.print(c+""+count);
}
}
}
}
发表于 2020-05-19 20:50:10
回复(0)
0
用一个数字记录即可
#include
(720)#include
#include
using namespace std;
int main(){
int ch[255]={0};//作标记
char cc[100005];
scanf("%s",cc);
for(int i=0;i
ch[cc[i]]++;
}
for(int i='a';i<='z';i++){
if(ch[i])printf("%c%d",i,ch[i]);
}
printf("\n");
return 0;
}
发表于 2020-05-17 13:42:27
回复(0)
java对字符串归一化_字符串归一化相关推荐
- delphi 字符串占用空间_字符串在Python内部是如何省内存的
起步 Python3 起,str 就采用了 Unicode 编码(注意这里并不是 utf8 编码,尽管 .py 文件默认编码是 utf8 ). 每个标准 Unicode 字符占用 4 个字节.这对于内 ...
- 对数坐标归一化_数据归一化,标准化的几种方法
归一化方法(Normalization Method) 1. 把数变为(0,1)之间的小数 主要是为了数据处理方便提出来的,把数据映射到0-1范围之内处理,更加便捷快速,应该归到数字信号处理范畴之内. ...
- mongodb 字符串 截取_字符串截取
字符串: 一:substr() substr() 方法可在字符串中抽取从 start 下标开始的指定数目的字符. stringObject.substr(start,length) 参数描述 star ...
- 均值归一化_数据归一化
数据归一化 [TOC] 将所有的数据映射到同一尺度. 首先,为什么需要数据归一化?举个简答的例子.样本间的距离时间所主导,这样在样本1以[1, 200]输入到模型中去的时候,由于200可能会直接忽 ...
- java字符串拼接_字符串拼接,什么时候会走StringBuilder?
☞ 程序员进阶必备资源免费送「21种技术方向!」 ☜ 粉丝福利: 专属优惠码4折优惠,当当网买书满400-230(点击查看) 前言 最近在突然想到了 String 字符串拼接问题,于是做了一个 dem ...
- java枚举比较大小写_字符串与Java枚举的不区分大小写的匹配
Java为每个Enum< T>提供一个valueOf()方法.对象,所以给出一个枚举 public enum Day { Monday, Tuesday, Wednesday, Thurs ...
- JAVA的MySQL字符串拼接_字符串的拼接-MYSQL
SQL允许两个或者多个字段之间进行计算,字符串类型的字段也不例外.比如我们需要以"工号+姓名"的方式在报表中显示一个员工的信息,那么就需要把工号和姓名两个字符串类型的字段拼接计算: ...
- java 删除指定字符_字符串删除指定位置字符 JAVA 删除字符串中指定的字符
<死侍2>有多不按套路出牌? 要CSS布局HTML小编今天和大家分享用到函数的调用. 编制函数fun,其功能是:删除一个字符串中指定的一.问题描述:从键盘输入一个字符串给str和一个字符给 ...
- java string 前缀匹配_字符串前缀和后缀匹配
娜 娜费劲九牛二虎之力终于把糖果吃完了(说好的吃不完呢?骗人,口亨~),于是,缘溪行,忘路之远近.忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤 纷,娜娜甚异之.复前行,欲穷其林.林尽水源,便得一 ...
最新文章
- 某团技术拷问:ArrayList 和 LinkedList 哪个更占空间?
- 推荐一些C++经典书籍
- 【域渗透】教你怎么利用DCSync导出域内所有用户hash
- html 桌面截图,如何使用javascript在html中截取屏幕截图?
- 【动态规划】石子合并
- 【转】SPSite、SPWeb对象模型(转winos.cn)
- 爱奇艺PPS如何登陆账号
- CTS(18)---Google GMS
- oracle数据库监听问题,分享一个有意思的Oracle19c数据库监听异常
- Mysql binlog 解析
- Spring ApplicationListener 事件监听器,能监听容器中所有实例
- 自己动手写操作系统(高清图书+源代码)分享
- 动听百年:音乐播放器发展沉浮史
- 如何通过抖音来进行广告宣传
- 图解数据分析(4) | 核心步骤1 - 业务认知与数据初探(数据科学家入门·完结)
- 理解path.join() 和 path.resolve()
- 正态分布(用python画出相应的图)
- Python随机车牌;京牌摇号⼩程序
- Ogre3D基础教程一
- 最大流算法模板:EK和dinic算法
热门文章
- UpdatePanel的简单用法(1)
- 由于之前的分页链接url不规范,导致百度爬虫搜索到死链接
- 什么是mongoose?
- 网上书店程序——html+css实现
- 地壳中元素含量排名记忆口诀_地球上的化学元素含量排名从多到少,是怎样排名的呢(不是地壳,也不是大气)?...
- ipmi-linux
- 【无标题】OrientDB Java连接操作
- Ubuntu20.4下x264、x265、fdk-aac和FFmpeg4.3源码编译安装
- xml java jaxb_JAXB java类与xml互转
- arm linux kdump,linux系统奔溃之vmcore:kdump 的亲密战友 crash