狂拽斌少


私信TA

用户名:dotcpp0699749

访问量:625

签 名:

ggs yyds dddd

等  级
排  名 20
经  验 19032
参赛次数 0
文章发表 15
年  龄 0
在职情况 学生
学  校 广州工商学院
专  业

  自我简介:

注意,这道题有个测试数据有问题!!!
参考代码:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
	char str[80000],*t=NULL;
	gets(str);
	t = strtok(str," ,");
	// 初始化第一个单词 
	char *wordmax=NULL,*wordmin=NULL;
	wordmax=(char *)realloc(wordmax,(strlen(t)+1)*sizeof(char));
	wordmin=(char *)realloc(wordmin,(strlen(t)+1)*sizeof(char));
	strcpy(wordmax,t);
	strcpy(wordmin,t);
	while(t!=NULL)
	{
		t = strtok(NULL," ,");
		if(t==NULL)
			break;
		else
		{
			if(strlen(t)>strlen(wordmax))
			{
				wordmax=(char *)realloc(wordmax,(strlen(t)+1)*sizeof(char));
				strcpy(wordmax,t);
			}
			if(strlen(t)<strlen(wordmin))
			{
				wordmin=(char *)realloc(wordmin,(strlen(t)+1)*sizeof(char));
				strcpy(wordmin,t);
			}
		}
	}
	printf("%s\n%s",wordmax,wordmin);
}
 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区