|
发表于 2014-2-20 22:30:51
|
显示全部楼层
不要意思,刚才贴的格式不对- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #define MAX_CHAR_PER_SENTENCE 200
- int get_sentence(char* sentence);
- void convert( char* input, char* output );
- int main() {
- char input_sentence[MAX_CHAR_PER_SENTENCE];
- char output_sentence[MAX_CHAR_PER_SENTENCE];
- while( get_sentence(input_sentence) ) {
- convert( input_sentence, output_sentence );
- printf("%s", output_sentence);
- //printf( "%s\n", input_sentence );
- }
- }
- int get_sentence(char* sentence) {
- int i = 0;
- while( scanf("%c",&sentence[i]) != EOF) {
- if( sentence[i] != '.' ) ++i;
- else {
- sentence[++i] = 0;
- return 1;
- }
- }
- return 0;
- }
- void convert( char* input, char* output ) {
- //找句子最大元素偏移量
- int i = 0, max_index = 0, mid;
- char max = input[max_index];
- while( input[i] != '.' ) {
- if( input[i] > max ) {
- max_index = i;
- max = input[i];
- }
- ++i;
- }
- mid = max_index + 1;//最大元素后面
- //拷贝最大元素之前
- strncpy( output, input, mid );
- output[mid]=0;
- //标记
- strcat( output, "(max)" );
- //拷贝最大元素之后
- strcat( output, input+mid );
- }
复制代码 |
|