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( ...
随机推荐
- (转)Java中的static关键字解析
转载: http://www.cnblogs.com/dolphin0520/p/3799052.html 一.static关键字的用途 在<Java编程思想>P86页有这样一段话: &q ...
- [LeetCode] Rotate Array 旋转数组
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...
- [LeetCode] Intersection of Two Linked Lists 求两个链表的交点
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- NCspider项目总结
下午就要答辩了,想把项目经历再总结一下. 项目分三个阶段. 第一阶段,是信息搜集整理阶段 要想法设法从各个门户网站上抓取到新闻和对应的评论数据.首先要分析网站结构. 1. 从哪里找到网站每日发布的所有 ...
- 三款不错的图片压缩上传插件(webuploader+localResizeIMG4+LUploader)
涉及到网页图片的交互,少不了图片的压缩上传,相关的插件有很多,相信大家都有用过,这里我就推荐三款,至于好处就仁者见仁喽: 1.名气最高的WebUploader,由Baidu FEX 团队开发,以H5为 ...
- jQuery遍历checkbox
$("input[type='checkbox']").each(function(){ var value = $(this).val(); //获得值 $(this).attr ...
- 玩转Redis之Window安装使用(干货)
距离上次定Gc.Db框架,好久没有更新博客了,今日没什么事,就打算就Redis写点东西. Redis是一个开源(BSD许可),内存存储的数据结构服务器,可用作数据库,高速缓存和消息队列代理.它支持字符 ...
- 图解TCP-IP协议
本文通过图来梳理TCP-IP协议相关知识.TCP通信过程包括三个步骤:建立TCP连接通道,传输数据,断开TCP连接通道.如图1所示,给出了TCP通信过程的示意图. 图1 TCP 三次握手四次挥手 图1 ...
- CSS Hack
CSS HACK,网上有很多,主要是IE版本不同造成的,尽量不要用CSS HACK,实在调不过去可以用一用,相信以后随着IE低版本的淘汰,CSS HACK也将不在使用. 类内部HACK IE6识别 - ...
- 【BZOJ-1656】The Grove 树木 BFS + 射线法
1656: [Usaco2006 Jan] The Grove 树木 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 186 Solved: 118[Su ...