次题比较简单,直接贴源码
/*
************************************************************************************************************************
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 substr
3. 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 3
struct 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;
}