给定一个字符串,请你将字符串重新编码,将连续的字符替换成“连续出现的个数+字符”。比如字符串AAAABCCDAA会被编码成4A1B2C1D2A。

输入描述:

每个测试输入包含1个测试用例
每个测试用例输入只有一行字符串,字符串只包括大写英文字母,长度不超过10000。

输出描述:

输出编码后的字符串

输入例子:

AAAABCCDAA

输出例子:

4A1B2C1D2A

牛客网页运行代码如下:

using System;
public class Program{
public static void Main(){
string input = System.Console.ReadLine();
int inputLength = input.Length;
int keyCount = ;
char keyValue;
char[] c = new char[inputLength];
for (int i = ; i < inputLength; i++)
{
c[i] = Convert.ToChar(input.Substring(i, ));
}
for (int i = ; i < inputLength; )
{
keyValue = c[i];
while (i != inputLength && keyValue == c[i])
{
i++;
keyCount++;
}
Console.Write("{0}{1}", keyCount, keyValue);
keyCount = ;
}
Console.ReadKey();
}
}

VS中的代码如下:

using System;

namespace 字符串编码
{
class Program
{
static void Main(string[] args)
{
string input = System.Console.ReadLine();
int inputLength = input.Length;
int keyCount = ;
char keyValue;
char[] c = new char[inputLength];
for (int i = ; i < inputLength; i++)
{
c[i] = Convert.ToChar(input.Substring(i, ));
}
for (int i = ; i < inputLength; )
{
keyValue = c[i];
while (i != inputLength && keyValue == c[i])
{
i++;
keyCount++;
}
Console.Write("{0}{1}", keyCount, keyValue);
keyCount = ;
}
Console.ReadKey();
}
}
}

欢迎交流。

最新文章

  1. 5.如何使主机和虚拟机IP处于同一网段(内网渗透专用)
  2. Python—函数的参数组合
  3. autoprefixer
  4. catch的执行与try的匹配
  5. OpenMP多线程linux下的使用,简单化
  6. easyui源码翻译1.32--Draggable(拖动)
  7. 李洪强iOS开发Swift篇—08_函数(2)
  8. JMeter分布式性能测试
  9. 正式学习React(四) 前序篇
  10. RESTful架构3--开发实战
  11. Team Queue (HDU:1387)
  12. 《Spring Boot 入门及前后端分离项目实践》目录
  13. P1080 国王游戏 贪心 高精度
  14. java反射对实体类取值和赋值
  15. 双系统安装Ubuntu
  16. uCrop图片裁剪
  17. last individual reading task 12061183叶露婷
  18. 4.update更新和delete删除用法
  19. windows 通过Web.config添加mimetype映射
  20. Linux下Setuid命令! 转载

热门文章

  1. 如何悄悄地提升MySQL用户权限
  2. FastDFS分布文件系统Java客户端集成
  3. rhel5.4+oracle 10g rac
  4. 前端- html 和css
  5. (转)如何最佳地使用memcached?
  6. NTP 服务器搭建
  7. PowerDesigner常用功能介绍
  8. unigui发展路线图
  9. (25)uniGUI for C++ builder之UniHTMLMemo初使用及uniGUI如何调用javaScript
  10. 设置cxGrid中RichEdit输入内容的格式