HDU1020字符串操作
#include <stdio.h>
#include <string.h>
int N;
int size; void main()
{
scanf("%d", &N);
getchar(); //读取残留的回车符
for(int i = ; i < N; i++)
{
int index = ;
char strIn[] = {'\0'};
char strOut[] = {'\0'};
int count['Z'] = {'\0'}; gets(strIn); //从键盘读取字符串
size = (int)strlen(strIn);
for(int j = ; j < size; j++)
{
if(strIn[j] >= 'A' && strIn[j] <= 'Z')
{
count[strIn[j]]++; //统计字母个数
}
else
return;
}
for(int i = 'A'; i < 'Z'; i++) //输出每个字母的个数
{
if(count[i] != ) //如果输入的字符串包含此字符
{
if(count[i] == )
{
strOut[index++] = i;
}
else
{
int len = ;
char str[] = {'/0'};
//strOut[index++] = count[i] + '0'; //统计相同字符个数
len = sprintf(str, "%d", count[i]);
strcat(&strOut[index], str);
index += len;
strOut[index++] = i;
}
}
}
printf("%s\n", strOut);
}
}![]()
#include <stdio.h>
#include <string.h>
int N;
int size; void main()
{
scanf("%d", &N);
getchar(); //读取残留的回车符
for(int i = ; i < N; i++)
{
char strIn[] = {'\0'}; gets(strIn); //从键盘读取字符串
size = (int)strlen(strIn);
for(int j = ; j < size;)
{
int k = ;
if(strIn[j] >= 'A' && strIn[j] <= 'Z')
{
char temp = '\0';
temp = strIn[j];
j++;
k = ;
while(strIn[j] == temp) //判断接下来是否有相同的字母
{
j++;
k++; //统计相同的字母个数
}
//输出个数和字母
if(k > )
printf("%d", k);
printf("%c",temp);
}
}
printf("\n");
}
}

W~A%SV_M}Q(QY$99SL.png)
W~A%SV_M}Q(QY$99SL.png)
HDU1020字符串操作的更多相关文章
- python学习笔记(字符串操作、字典操作、三级菜单实例)
字符串操作 name = "alex" print(name.capitalize()) #首字母大写 name = "my name is alex" pri ...
- shell编程常用的截取字符串操作
1. 常用的字符串操作 1.1. 替换字符串:$ echo ${var/ /_}#支持正怎表达式 / /表示搜索到第一个替换,// /表示搜索到的结果全部替换. ...
- php字符串操作集锦
web操作, 主要就是对字符文本信息进行处理, 所以, 字符串操作几乎占了很大一部分的php操作.包括 注意strstr 和 strtr的区别? 前者表示字符串查找返回字符串,后者表示字符串中字符替换 ...
- java 字符串操作和日期操作
一.字符串操作 创建字符串 String s2 = new String("Hello World"); String s1 = "Hello World"; ...
- [No000078]Python3 字符串操作
#!/usr/bin/env python3 # -*- coding: utf-8 -*- '''Python 字符串操作 string替换.删除.截取.复制.连接.比较.查找.包含.大小写转换.分 ...
- Python 字符串操作及string模块使用
python的字符串操作通过2部分的方法函数基本上就可以解决所有的字符串操作需求: python的字符串属性函数 python的string模块 1.字符串属性方法操作: 1.>字符串格式输出对 ...
- C语言字符串操作总结大全
1)字符串操作 strcpy(p, p1) 复制字符串 函数原型strncpy(p, p1, n) 复制指定长度字符串 函数原型strcat(p, p1) 附加字符串 函数原型strn ...
- c# 字符串操作
一.字符串操作 //字符串转数组 string mystring="this is a string" char[] mychars=mystring.ToCharArray(); ...
- C语言字符串操作总结大全(超详细)
本篇文章是对C语言字符串操作进行了详细的总结分析,需要的朋友参考下 1)字符串操作 strcpy(p, p1) 复制字符串 strncpy(p, p1, n) 复制指定长度字符串 strcat( ...
随机推荐
- ORACLE 利用 REPLACE函数替换字段字符串
REPLACE(string,s1,s2) string 希望被替换的字符或变量 s1 被替换的字符串 s2 要替换的字符串 SQL> select replace(he love you,he ...
- [LeetCode] Find K Pairs with Smallest Sums 找和最小的K对数字
You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Sqrt(x) 求平方根
Implement int sqrt(int x). Compute and return the square root of x. 这道题要求我们求平方根,我们能想到的方法就是算一个候选值的平方, ...
- 【深度学习Deep Learning】资料大全
最近在学深度学习相关的东西,在网上搜集到了一些不错的资料,现在汇总一下: Free Online Books by Yoshua Bengio, Ian Goodfellow and Aaron C ...
- Docker的安装
目前Docker可以在Linux系统.Windows系统,这个文档介绍3种安装方式,安装Docker版本为1.8.2 具备安装Docker的条件: 64位CPU架构的设备 Linux系统内核推荐3.1 ...
- jquery-leonaScroll-1.3-自定义竖向自适应滚动条插件
下载链接地址:https://share.weiyun.com/9ac3ca3fb29648bb1aad1b83a76b123c (密码:4y9t)[含mini版] 欢迎使用leonaScroll-1 ...
- Backbone.js应用基础
前言: Backbone.js是一款JavaScript MVC应用框架,强制依赖于一个实用型js库underscore.js,非强制依赖于jquery:其主要组件有模型,视图,集合,路由:与后台的交 ...
- BootStrap学习笔记,优缺点总结
本篇约定Bootstrap简写为BT BT的受欢迎程度是大家有目共睹的,用它可以快速的搭建出网站.很早就接触过这个框架,其中的栅格系统,css模块化以及js插件做的相当不错,由于工作中较少使用也一 ...
- 【URAL 1519】Formula 1
http://acm.timus.ru/problem.aspx?space=1&num=1519 调了好久啊.参考(抄)的iwtwiioi的题解. 如果想要题解,题解在<基于连通性状态 ...