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( ...
随机推荐
- Linux 信号(一)—— kill 函数
世事并无好坏之分,全看我们怎么去想.—— 哈姆雷特·第二幕第二景 ilocker:关注 Android 安全(新入行,0基础) QQ: 2597294287 #include <signal.h ...
- 用java String类的getBytes(String charsetName)和String(byte[] bytes, String charsetName)解决乱码问题
Java中String的数据是如何存储的,查看源代码就可以知道,String的数据是存储在char[] value这样一个成员变量中的,char类型的大小在java中是2个字节 我们还知道,现在普遍使 ...
- url转码
var target = encodeURI('我测试'); //--> target = %E6%88%91%E6%B5%8B%E8%AF%95 var afterConvert = deco ...
- CentOS 配置MySQL允许远程登录
Mysql为了安全性,在默认情况下用户只允许在本地登录,可是在有此情况下,还是需要使用用户进行远程连接,因此为了使其可以远程需要进行如下操作: 一.允许root用户在任何地方进行远程登录,并具有所有库 ...
- 深度掌握SVG路径path的贝塞尔曲线指令
一.数字.公式.函数.变量,哦,NO! 又又一次说起贝塞尔曲线(英语:Bézier curve,维基百科详尽中文释义戳这里),我最近在尝试实现复杂的矢量图形动画,发现对贝塞尔曲线的理解馒头那么厚,是完 ...
- JsonResult作为Action返回值时的错误
JsonResult作为Action返回值时的错误 System.InvalidOperationException: This request has been blocked because ...
- Openjudge 1.13-21:最大质因子序列(每日两水)
总时间限制: 1000ms 内存限制: 65536kB 描述 任意输入两个正整数m, n (1 < m < n <= 5000),依次输出m到n之间每个数的最大质因子(包括m和n ...
- Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...
- atom无法安装插件的解决方法之一
atom通过setting中无法下载插件,通过apm也无法下载插件,可能是网络.config配置的问题,不好解决. 下面的方法全手动,基本属于万金油方法: 1,在atom的setting页面中点击op ...
- linux重启mysql无法启动
如VPS新建后,重启则无法启动,出现类似 Starting MySQL ... * The server quit without updating PID file (/var/run/mysqld ...