求三个字符串的长度,并输出最长值和最短值及其长度
来源:互联网 发布:中级程序员考证培训费 编辑:程序博客网 时间:2024/06/13 12:23
//////////////////////////////////////////////////////
//求三个字符串的长度,并输出最长值和最短值及其长度
/////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* strLenCmp(char* x,char* y,int* Len,int flag);
main()
{
char *str1="I am LYC." ;
char *str2="My english name is Daniel.";
char *str3="Could I make friend with you?";
char *strSht=NULL;
char *strLng=NULL;
int shtLen=0,lngLen=0;
printf("The three strings are:\n%s\n%s\n%s\n",str1,str2,str3);
strSht=strLenCmp(strLenCmp(str1,str2,&shtLen,0),str3,&shtLen,0); //求最短者
strLng=strLenCmp(strLenCmp(str1,str2,&lngLen,1),str3,&lngLen,1); //求最长者
printf("The shortest string and its length are:\n%s\n%d\n",strSht,shtLen);
printf("The longest string and its length are:\n%s\n%d\n",strLng,lngLen);
system("pause");
}
char* strLenCmp(char* x,char* y,int* Len,int flag)
{
int xLen,yLen;
xLen=strlen(x);
yLen=strlen(y);
char *temp=NULL;
switch(flag)
{ case 0:
{
if(xLen<yLen)
{
*Len=xLen;
temp=x;
}
else
{
*Len=yLen;
temp=y;
}
return temp;
}
case 1:
{
if(xLen<yLen)
{
*Len=yLen;
temp=y;
}
else
{
*Len=xLen;
temp=x;
}
return temp;
}
default: break;
}
}
//求三个字符串的长度,并输出最长值和最短值及其长度
/////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* strLenCmp(char* x,char* y,int* Len,int flag);
main()
{
char *str1="I am LYC." ;
char *str2="My english name is Daniel.";
char *str3="Could I make friend with you?";
char *strSht=NULL;
char *strLng=NULL;
int shtLen=0,lngLen=0;
printf("The three strings are:\n%s\n%s\n%s\n",str1,str2,str3);
strSht=strLenCmp(strLenCmp(str1,str2,&shtLen,0),str3,&shtLen,0); //求最短者
strLng=strLenCmp(strLenCmp(str1,str2,&lngLen,1),str3,&lngLen,1); //求最长者
printf("The shortest string and its length are:\n%s\n%d\n",strSht,shtLen);
printf("The longest string and its length are:\n%s\n%d\n",strLng,lngLen);
system("pause");
}
char* strLenCmp(char* x,char* y,int* Len,int flag)
{
int xLen,yLen;
xLen=strlen(x);
yLen=strlen(y);
char *temp=NULL;
switch(flag)
{ case 0:
{
if(xLen<yLen)
{
*Len=xLen;
temp=x;
}
else
{
*Len=yLen;
temp=y;
}
return temp;
}
case 1:
{
if(xLen<yLen)
{
*Len=yLen;
temp=y;
}
else
{
*Len=xLen;
temp=x;
}
return temp;
}
default: break;
}
}
- 求三个字符串的长度,并输出最长值和最短值及其长度
- 005求一个字符串中出现相同且长度最长的字符串,输出它及其首字符位置
- 求二叉树中的第一条最长路径长度,并输出最长路径上的节点
- 寻找字符串中的最长数字字符串并输出长度
- 求一个字符串中最长连续字串及其长度
- 求字符串中相同且长度最长的字符串及其首字母的位置
- 求最长递增子序列长度并输出序列
- 求已知字符串的最大回文字符串长度,并输出该字符串
- Java实现求最长增长子序列长度,并输出该子序列值
- 写一函数,求一个字符串的长度。在main函数中输入字符串,并输出其长度。(指针)
- 写一个方法,求一个字符串的长度,在main函数中输入字符串,并输出其长度。
- 写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度
- java 写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度。
- 找出字符串中最长的数字子串并指出位置长度,输出。
- 求两个字符串中最长连续子字符串的长度
- 求字符串中最长对称字符串的长度
- 求字符串长度并返回
- 找出字符串中出现重复而且长度最长的字符串,并且输出而且输出其长度
- struts2 set标签
- Ubuntu12.04安装Sun JDK 6u32
- Android应用开发提高系列(5)——Android动态加载(下)——加载已安装APK中的类和资源
- 查看本机DNS linux
- CAAnimation
- 求三个字符串的长度,并输出最长值和最短值及其长度
- 数据库的逻辑层类,用一个基类进行实现
- power Designer VBS 脚步 通过 excel 生成实体,不用一个一个的输入。
- 音频处理领域的瑞士军刀──SoX
- poj 2185(流的最小费用的充要条件)消负圈
- POJ 2318 TOYS (点与线段关系)
- Java、Tomcat、Android环境变量配置
- 具体的数据库操作类,Model类和DB类
- Pseudoclasses :first-child and :last-child for IE6