The operation on charactor string to compress the same alphabets

Objective

input abacacdekb , output 3a 2b 2c 1d 1e 1k

Procesure

#include<stdio.h>
#include<stdlib.h>
char a[]={'a','b','a','c','a','c','d','e','k','b'};
typedef char key_type;
typedef struct node{
	key_type key;
	struct node *next;
	int count;
}node, *pnode;

void insert(pnode *root, key_type key)
{
	pnode p = (pnode)malloc(sizeof(node));

	p->key = key;
	p->next = NULL;
	p->count = 1;

	if( (*root) == NULL)
	{
		( *root ) = p;

		return ;
	}
	insert(&(*root)->next,key);
}
int find(pnode root, key_type key)
{

	if( root ==NULL )
		return 0;

	while( root && key != root->key)
	{
		root =root->next;
	}
	if( root == NULL)
		return 0;
	if( key == root->key)
	{
		(root->count) = (root->count)+1;
		return 1 ;
	}

}
void read(pnode *root )
{
	pnode temp =(*root);
	while(temp)
	{
		printf("%d%c ",temp->count,temp->key);
		temp = temp->next;
	}
}
void main()
{
	int i;
	pnode root = NULL ;
	for(i=0;i<10;i++)
	{
		if( find( root , a[i] ) == 0 )
			insert(&root,a[i]);
		else
			continue;
	}
	read(&root);

}
时间: 2024-10-30 21:42:39

The operation on charactor string to compress the same alphabets的相关文章

Operation on character string to delete same alphabet

#include<stdio.h> #include<stdlib.h> char a[]={'a','b','a','c','a','c','d','e','k','b'}; typedef char key_type; typedef struct node{ key_type key; struct node *next; }node, *pnode; void insert(pnode *root, key_type key) { pnode p = (pnode)mall

Check if a string is NULL or EMPTY using PowerShell

http://techibee.com/powershell/check-if-a-string-is-null-or-empty-using-powershell/1889 Check if a string is NULL or EMPTY using PowerShellby TECHIBEE on OCTOBER 10, 2012 In this post, I will show you how to verify if a string is empty, null or havin

String 经常用法最优算法实现总结 (二)

1. String getOrderedString(boolean isDuplicated, String - str) 说明: Orders all characters in the input strings and return the ordered string.(note: only considering the alphabets and digits) i.e: (false, {"ahcdx", "abcuy", "cejm&qu

String 常用方法最优算法实现总结 (二)

1. String getOrderedString(boolean isDuplicated, String - str) 说明: Orders all characters in the input strings and return the ordered string.(note: only considering the alphabets and digits) i.e: (false, {"ahcdx", "abcuy", "cejm&qu

Java性能提示(全)

http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLists and ArrayLists (and Vectors) (Page last updated May 2001, Added 2001-06-18, Author Jack Shirazi, Publisher OnJava). Tips: ArrayList is faster than

C++ Core Guidelines

C++ Core Guidelines September 9, 2015 Editors: Bjarne Stroustrup Herb Sutter This document is a very early draft. It is inkorrekt, incompleat, and pµøoorly formatted. Had it been an open source (code) project, this would have been release 0.6. Copy

P3102 [USACO14FEB]秘密代码Secret Code

题目描述 Farmer John has secret message that he wants to hide from his cows; the message is a string of length at least 2 containing only the characters A..Z. To encrypt his message, FJ applies a sequence of "operations" to it, where an operation ap

PHP 加密 和 解密 方法

关于Discuz的加密解密函数,相信大家都有所了解,该authcode函数可以说是对PHP界作出了重大的贡献,真的发觉discuz这个函数写的太精彩啦. 研究了一下这个算法,总的来说可以归纳为以下三点: 1,动态性,同一字符串使用相同的key,每次加密的密文都不一样,而解密方法只有一个,其实就是把解密的信息放到了密文上面. 2,时效性,可以自己加一个限期参数,以秒为单位,这个其实就是在密文里加入了有效时间. 3,统一性,加密和解密都用同一个函数,而且用了比较简单的异或算法. 由于该函数具有以上功

Beetl2.2使用说明书20151201

李家智<[email protected]> Table of Contents 1. 什么是Beetl 2. 基本用法 2.1. 从GroupTemplate开始 2.2. 模板基础配置 2.3. 模板资源加载器 2.4. 定界符与占位符号 2.5. 注释 2.6. 临时变量定义 2.7. 全局变量定义 2.8. 共享变量 2.9. 模板变量 2.10. 引用属性 2.11. 算数表达式 2.12. 逻辑表达式 2.13. 循环语句 2.14. 条件语句 2.15. try-catch 2.