POJ——字符串插入(AC)
来源:互联网 发布:北大青鸟报警设备编程 编辑:程序博客网 时间:2024/05/16 00:49
次题比较简单,直接贴源码
/*************************************************************************************************************************1. Description:There are two strings, named as “str” and “substr”. The number of characters in “str”is less than 10 and the number of characters in “substr” is 3.The number of characters does not contain the ending ‘\0’.We will insert “substr” into “str” after the character with the max ASCII code in“str”. We will insert at the firstmax-ASCII-code character if there are not only one.2. Input:The input contains many lines, and each line is a test case in the form of:str substr3. Output:Output the results in each case.4. Example: input: abcab eee 12345 555 output: abceeeab 12345553**************************************************************************************************************************/#include <stdlib.h>#include <stdio.h>#include <string.h>#define BUF_SIZE 20#define SIZE_STR 10#define SIZE_SUB 3struct tagNode{struct tagNode *next;char buf[ SIZE_STR+SIZE_SUB+2 ];};char _tmpbuf[SIZE_STR];int main(void){size_t len = BUF_SIZE;char *line = (char*)malloc(len); char *str, *substr;int i,j;struct tagNode *head = (struct tagNode*)malloc(sizeof(struct tagNode));struct tagNode *tail = head;struct tagNode *nnode = NULL;head->next = NULL;while( -1 != getline(&line,&len , stdin) ){int c = 0;int p = 0;str = strtok(line," ");substr = strtok(NULL," \n");for ( i=0; str[i] != '\0'; i++ ){if ( str[i] > c ){c = str[i];p = i;}}for ( j=0; j<i-p-1; j++ )_tmpbuf[ j ] = str[ p+j+1 ];str[ ++p ] = substr[ 0 ];str[ ++p ] = substr[ 1 ];str[ ++p ] = substr[ 2 ];for ( i=0; i<j; i++ )str[ ++p ] = _tmpbuf[ i ];str[ ++p ] = 0;/*printf("%s\n",str);*//* list insert */nnode = (struct tagNode*)malloc(sizeof(struct tagNode));strcpy(nnode->buf,str);nnode->next = NULL;tail->next = nnode;tail = nnode;}for ( tail=head->next; tail!=NULL; tail=tail->next ){printf("%s\n",tail->buf);}return 0;}
- POJ——字符串插入(AC)
- POJ——多项式加法(AC)
- POJ 字符串插入
- POJ——用队列对扑克牌排序(AC)
- POJ——栈的基本操作(AC)
- leetcode——Insertion Sort List 对链表进行插入排序(AC)
- 十五周—插入字符串
- leetcode——Reverse Words in a String 旋转字符串中单词顺序(AC)
- leetcode——String to Integer (atoi) 字符串转换为整型数(AC)
- leetcode——Implement strStr() 实现字符串匹配函数(AC)
- 匹配多个字符串——AC自动机
- AC自动机2——KMP字符串匹配算法
- 第十六周—C语言(字符串的插入)
- poj 1204:Word Puzzles(AC自动机)
- poj - 1204 - Word Puzzles(AC自动机)
- poj 2222 Keywords Search(AC自动机)
- POJ 1204 Word Puzzles(AC自动机)
- POJ 4052 Hrinity(AC自动机)
- l138地址-TI支持
- Android ADT 无法在线安装,离线下载ADT压缩包方法。SDK Manager无法更新
- Linux文件权限详解
- Photosho cs5 面板插件开发笔记04
- ffdshow 源代码分析 9: 编解码器有关类的总结
- POJ——字符串插入(AC)
- 数据库--SQL SERVER 和ACCESS 查询表名
- vim基本命令
- POJ 2955 Brackets 括号匹配 区间DP
- Android使用自定义AlertDialog(退出提示框)
- 2014找工作----扎实的基础和开阔的视野是企业最看重的因素
- 堆排序
- maven环境的搭建和使用
- 20-JavaScript-面向对象-类(原型对象) 和 对象(实例)