Problem Description
Given a string containing only 'A' - 'Z', we could encode it using the following method:

1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string.

2. If the length of the sub-string is 1, '1' should be ignored.

Input
The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only 'A' - 'Z' and the length is less than 10000.

Output
For each test case, output the encoded string in a line.

Sample Input
2
ABC
ABBCCC

Sample Output
ABC
A2B3C

1个回答

``````#include<stdio.h>
#include<string.h>
char str[10001];
char result[10001];
int main()
{
int numTest,i,j,k;
int strLen;
int resIdx;
scanf("%d",&numTest );
while(numTest--)    {
scanf("%s",str);
strLen = strlen(str);
resIdx = 0;                                  //initialize the result index for each test Case
for(i=0; i<strLen; i++)     {
for(j=i, k=0; j<strLen ; k++, j++)          {
if(str[i]!=str[j])
break;
}
if(k>1) {
result[resIdx++]='0'+k;   //convert the number into char
}
result[resIdx++]=str[i];       // copy the original char
i=j-1;                                   //move the i to the point before next different point
}                                            // the i++ in the outer loop will move i to next differnt point
result[resIdx]=0;                  // null the end of each result, since it maybe shorter than last result
printf("%s\n",result);
}
return 0;
}

``````

C++版数据结构哈夫曼树程序设计：实现对26个英文字母的编码和译码

C++版数据结构哈夫曼树程序设计 项目一：实现对26个英文字母的编码和译码，设计完成以下功能： 1.能够对27个字符进行编码、并存储。 2.利用编码能够实现任意英文句子的编码操作，并存储编码。 3.能够将二进制的密码翻译成句子，并将译文存储。 4.能随时查看字母的编码。 5.使用文件去存储相关内容。

Problem Description The cows are thrilled because they've just learned about encrypting messages. They think they will be able to use secret messages to plot meetings with cows on other farms. Cows are not known for their intelligence. Their encryption method is nothing like DES or BlowFish or any of those really good secret coding methods. No, they are using a simple substitution cipher. The cows have a decryption key and a secret message. Help them decode it. The key looks like this: yrwhsoujgcxqbativndfezmlpk Which means that an 'a' in the secret message really means 'y'; a 'b' in the secret message really means 'r'; a 'c' decrypts to 'w'; and so on. Blanks are not encrypted; they are simply kept in place. Input text is in upper or lower case, both decrypt using the same decryption key, keeping the appropriate case, of course. Input * Line 1: 26 lower case characters representing the decryption key * Line 2: As many as 80 characters that are the message to be decoded Output * Line 1: A single line that is the decoded message. It should have the same length as the second line of input. Sample Input eydbkmiqugjxlvtzpnwohracsf Kifq oua zarxa suar bti yaagrj fa xtfgrj Sample Output Jump the fence when you seeing me coming

Problem Description Given a string containing only 'A' - 'Z', we could encode it using the following method: 1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string. 2. If the length of the sub-string is 1, '1' should be ignored. Input The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only 'A' - 'Z' and the length is less than 10000. Output For each test case, output the encoded string in a line. Sample Input 2 ABC ABBCCC Sample Output ABC A2B3C

C语言文件简单加密与解密

C语言转换成大写，结果为什么不对？哪里错了

#include<stdio.h> #include<string.h> main() { char aa[]="Hello world"; int cd=strlen(aa); int i; for(i=0;i<cd;i++) if (97<=aa[i]<=122)aa[i]-=32; printf("%s",aa); }

C语言代码运行问题，为什么编译通过，但是运行时直接结束，无法输入？

#include<stdio.h> #include<stdlib.h> #define MAX 1000 //定义哈夫曼树 typedef struct tree { int weight; int parent; int lchild; int rchild; }HTNode,*HuffmanTree; //定义编码 typedef struct code { int bit[MAX]; int start; }HCNode,*HuffmanCode; //26个英文字母构造树 void HuffmanTreeing(HTNode HT[MAX]) { int i,j,s1,s2,x1,x2; for(i=0;i<51;i++) { HT[i].weight=0; HT[i].parent=0; HT[i].lchild=0; HT[i].rchild=0; } for(i=0;i<26;i++) { printf("请输入26个英文字母的权值:"); scanf("%d",&HT[i].weight); } for(i=0;i<25;i++) { s1=s2=MAX; x1=x2=0; for(j=0;j<26+i;j++) { if(HT[j].weight<s1&&HT[j].parent==0) { s1=HT[j].weight; } x1=j; } for(j=0;j<26+i;j++) { if(HT[j].weight<s2&&HT[j].parent==0&&j!=x1) { s2=HT[j].weight; } x2=j; } HT[x1].parent=26+i; HT[x2].parent=26+i; HT[26+i].weight=HT[x1].weight+HT[x2].weight; HT[26+i].lchild=x1; HT[26+i].rchild=x2; } } //编码 void HuffmanCoding(HTNode HT[MAX],HCNode HC[MAX]) { HCNode cd; int i,j,c,p; for(i=0;i<26;i++) { cd.start=25; c=i; p=HT[c].parent; while(p!=0) { if(HT[p].lchild==c) cd.bit[cd.start]=0; else cd.bit[cd.start]=1; cd.start--; c=p; p=HT[c].parent; } for(j=cd.start+1;j<26;j++) { HC[i].bit[j]=cd.bit[j]; } HC[i].start=cd.start; } printf("26位字母的编码是:\n"); for(i=0;i<26;i++) { printf("%c:","a"+i); for(j=HC[i].start+1;j<26;j++) { printf("%d",HC[i].bit[j]); } printf("\n"); } } int main() { HTNode HT[MAX]; HCNode HC[MAX]; HuffmanTreeing(HT); HuffmanCoding(HT,HC); return 0; }

A 基于哈夫曼树的数据压缩算法 时间限制(C/C++):1000MS/3000MS 运行内存限制:65536KByte 总提交:445 测试通过:131 描述 输入一串字符串，根据给定的字符串中字符出现的频率建立相应哈夫曼树，构造哈夫曼编码表，在此基础上可以对待压缩文件进行压缩（即编码），同时可以对压缩后的二进制编码文件进行解压（即译码）。 输入 多组数据，每组数据一行，为一个字符串（只考虑26个小写字母即可）。当输入字符串为“0”时，输入结束。 输出 每组数据输出2n+4行（n为输入串中字符类别的个数）。第一行为统计出来的字符出现频率（只输出存在的字符，格式为：字符：频度），每两组字符之间用一个空格分隔，字符按照ASCII码从小到大的顺序排列。第二行至第2n行为哈夫曼树的存储结构的终态（形如教材139页表5.2（b），一行当中的数据用空格分隔）。第2n+2行为每个字符的哈夫曼编码（只输出存在的字符，格式为：字符：编码），每两组字符之间用一个空格分隔，字符按照ASCII码从小到大的顺序排列。第2n+3行为编码后的字符串，第2n+4行为解码后的字符串（与输入的字符串相同）。 样例输入 aaaaaaabbbbbccdddd aabccc 0 样例输出 a:7 b:5 c:2 d:4 1 7 7 0 0 2 5 6 0 0 3 2 5 0 0 4 4 5 0 0 5 6 6 3 4 6 11 7 2 5 7 18 0 1 6 a:0 b:10 c:110 d:111 00000001010101010110110111111111111 aaaaaaabbbbbccdddd a:2 b:1 c:3 1 2 4 0 0 2 1 4 0 0 3 3 5 0 0 4 3 5 2 1 5 6 0 3 4 a:11 b:10 c:0 111110000 aabccc

linux下utf8编码转Unicode编码

#include<stdio.h> int main() { char a,b,c,t; scanf("%c%c%c",&a,&b,&c); if(a>b) {t=a;a=b;b=t;} if(a>c) {t=a;a=c;c=t;} if(b>c) {t=b;b=c;c=t;} printf("%c %c %c",a,b,c); return 0; }

MATLAB 在编程中出现的问题

Java基础知识面试题（2020最新版）

Intellij IDEA 实用插件安利

1. 前言从2020 年 JVM 生态报告解读 可以看出Intellij IDEA 目前已经稳坐 Java IDE 头把交椅。而且统计得出付费用户已经超过了八成（国外统计）。IDEA 的...

MySQL数据库面试题（2020最新版）

2020阿里全球数学大赛：3万名高手、4道题、2天2夜未交卷

HashMap底层实现原理，红黑树，B+树，B树的结构原理 Spring的AOP和IOC是什么？它们常见的使用场景有哪些？Spring事务，事务的属性，传播行为，数据库隔离级别 Spring和SpringMVC，MyBatis以及SpringBoot的注解分别有哪些？SpringMVC的工作原理，SpringBoot框架的优点，MyBatis框架的优点 SpringCould组件有哪些，他们...

《Oracle Java SE编程自学与面试指南》最佳学习路线图2020年最新版（进大厂必备）

​能让德国人放弃现金支付​，也没谁了