3.输入一串字符串,整理其中的数字和字母和符号,并分别输出
答案:3 悬赏:30
解决时间 2021-02-18 12:03
- 提问者网友:相思故
- 2021-02-17 20:01
3.输入一串字符串,整理其中的数字和字母和符号,并分别输出
最佳答案
- 二级知识专家网友:萌萌哒小可爱
- 2021-02-17 20:39
c 语言程序。用 gets(s); 读入 一行字符串。第一次循环判断一个个字符是否是数字,是则输出。第二次循环判断一个个字符是否是小写和大写字母,是则输出。第三次循环判断一个个字符是否是数字,是否是小写和大写字母,是则用 continue 跳过,不是则输出。
#include
int main()
{
char s[100];
int i;
printf("input the string:\n");
gets(s);
for (i=0;i
if (s[i]>='0' && s[i]<='9')putchar(s[i]);
}
printf("\n");
for (i=0;i
if ((s[i]>='a' && s[i]<='z')|| (s[i]>='A' && s[i]<='Z')) putchar(s[i]);
}
printf("\n");
for (i=0;i
if (s[i]>='0' && s[i]<='9') continue;
if ((s[i]>='a' && s[i]<='z')|| (s[i]>='A' && s[i]<='Z'))continue;
putchar(s[i]);
}
printf("\n");
return 0;
}
#include
int main()
{
char s[100];
int i;
printf("input the string:\n");
gets(s);
for (i=0;i
}
printf("\n");
for (i=0;i
}
printf("\n");
for (i=0;i
if ((s[i]>='a' && s[i]<='z')|| (s[i]>='A' && s[i]<='Z'))continue;
putchar(s[i]);
}
printf("\n");
return 0;
}
全部回答
- 1楼网友:而你却相形见绌
- 2021-02-17 22:05
要是我起床了,很热议为你效劳
- 2楼网友:怪咖小青年
- 2021-02-17 21:00
#include "stdio.h"
#include "string.h"
#include <ctype.h>
main()
{
char t[100],w[100]={0},max[100]={0};
int i,k,pos=0;
printf("输入字符串:");
gets(t);
for(i=0,k=0;t[i];i++)
{
if(isalpha(t[i]))//遇到字母
{
w[k++]=t[i];
}
if(!isalpha(t[i+1]))//如果不是
{
w[k]=0;k=0;
if(strlen(w)>strlen(max))
{
strcpy(max,w);
pos=i;
}
w[0]=0;
}
}
printf("最长单词是:%s\n",max);
printf("位置是%d,长度是%d\n",pos-strlen(max)+1,strlen(max));
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯