编码(链表)
来源:互联网 发布:java war包反编译 编辑:程序博客网 时间:2024/05/21 09:25
编码
Time Limit: 1000MS Memory limit: 65536K
题目描述
给你一个由大写字母组成的组成的字符串,你可以用如下规则对其进行编码:
1、 包含K个相同字母的连续字符串可以用KX表示,其中X是相同的字母。
2、 如果K为1,不输出K
输入
输入有多组,直到文件结束。每组一个字符串,长度为10000以内
输出
输出编码后的字符串。
示例输入
ABCABBCCC
示例输出
ABCA2B3C
#include <stdio.h>#include <stdlib.h>#include <string.h>struct node{ char data; struct node *next;};int main(){ char a[10000]; int i,k,t[10000]; while(gets(a)!=NULL) { struct node *head,*p,*tail,*q,*r; head=(struct node*)malloc(sizeof(struct node)); head->next=NULL; tail=head; k=strlen(a); for(i=0;i<k;i++) { p=(struct node*)malloc(sizeof(struct node)); p->next=NULL; p->data=a[i]; tail->next=p; tail=p; } p=head; i=0; while(p) { q=p; t[i]=1; while(q->next) { if(q->next->data==p->data) { t[i]++; r=q->next; q->next=r->next; free(r); } else break; } p=p->next; i++; } p=head->next; i=1; while(p) { if(t[i]!=1) printf("%d",t[i]); i++; printf("%c",p->data); p=p->next; } printf("\n"); q=head; while(head->next!=NULL) { r=q->next; q->next=r->next; free(r); } head->next=NULL; } return 0;}
0 0
- 编码(链表)
- BCD编码(8421编码)
- Huffman编码(哈夫曼编码),
- 字符编码(哈夫曼编码)
- 信源编码算法(费诺编码&&哈夫曼编码)
- 信源编码算法(费诺编码&哈夫曼编码)
- QR码编码原理二(编码)
- url 编码(percentcode 百分号编码)
- url 编码(percentcode 百分号编码)
- 【转】url 编码(percentcode 百分号编码)
- url 编码(percentcode 百分号编码)
- QR码编码原理二(编码)
- QR码编码原理二(编码)
- QR码编码原理二(编码)
- hufuman 编码实现(赫夫曼编码)
- java编码(四)编码错误例子
- 字符集(字符编码类型)编码格式
- QR码编码原理二(编码)
- android优秀开源项目
- Android 反射简化findViewById
- JavaScript常用表单验证
- C++产生随机序列算法
- yuv RGB h.264 vga都是什么意思,有什么关系
- 编码(链表)
- Android的系统架构
- 常见的内存错误
- ILdasm 的使用方法
- VI与文件查看
- 第八章:虚函数笔记(虚函数碉堡了)
- Objective-C的动态特性
- VisionMobile:M2M生态系统的秘方(2):一、完美风暴
- C++、C#写的WebService相互调用