C语言编程题 求解 c语言编程题,求解。

\u6c42\u89e3\u8fd9\u9053C\u8bed\u8a00\u7f16\u7a0b\u9898

#include #include #include int main(){char sub1[20],sub2[20],str[200],strtemp[200];scanf("%s %s",sub1,sub2);fflush(stdin);gets(str);strcpy(strtemp,str);int i,j;int len=strlen(str);int len_sub1=strlen(sub1);int len_sub2=strlen(sub2);for(i=0;i='A' && strtemp[i]='A' && sub1[i]<='Z'){sub1[i]+=32;}}int target_i=0;char target[500];j=0;for(i=0;i<len-len_sub1;i++){if(strtemp[i]==sub1[0]){int m=i;for(j=0;j<len_sub1;j++,m++){if(sub1[j]!=strtemp[m]){break;}}if(j==len_sub1){for(m=0;m<len_sub2;m++){target[target_i++]=sub2[m];}i=i+len_sub1;}}target[target_i++]=str[i];}target[target_i]='\0';printf("\n%s\n",target);return 0;}

\u6709\u9650\u5b9a\u6570\u591a\u5927\u5417\uff1f
#include
unsigned long long h2d(char *str) {

unsigned long long a;
sscanf(str, "%llx", &a);
return a;
}
int main() {
char hex[100];
scanf("%s", hex);
printf("%lld", h2d(hex));
return 0;
}

按照题意,表格使用结构链表实现。其中成员班级或工龄,使用自定义的联合体union(就是题目要求的共用体)。
函数异常不做处理,直接抛出,你需要可以在调用时判断处理异常。

#include <stdio.h>

#include <malloc.h>

typedef union info4

{

char cName[10];//班级名称

int wAge;//工龄

}IO4;

typedef struct stInfo

{

int id;//编号

char name[10];// 姓名

int pType;//职业类别:0表示学生,1表示教师

IO4 cwInfo;//对应职业类别的班级或工龄

struct stInfo *next;

}STINFO;

int inputInfo(STINFO **stHead,STINFO **stTail);//输入,调用一次输入一条信息,并生成或加入链表,成功返回1,失败返回0

void prfInfos(STINFO *stHead);// 打印链表

int main()

{

STINFO *stHead=NULL,*stTail=NULL;

int n=4;//测试就输入4个,需要自己改

while(n--)

if(!inputInfo(&stHead,&stTail))

{

printf("异常终止!
");

return 1;

}

prfInfos(stHead);

return 0;

}

void prfInfos(STINFO *stHead)// 打印链表

{

printf("编号   姓 名   职业 班级\\工龄
");

while(stHead->next)

{

printf("%d %9s %s",stHead->next->id,stHead->next->name,stHead->next->pType?"教师":"学生");

if(stHead->next->pType)

printf("%9d
",stHead->next->cwInfo.wAge);

else

printf("%9s
",stHead->next->cwInfo.cName);

stHead=stHead->next;

}

}

int inputInfo(STINFO **stHead,STINFO **stTail)//输入,调用一次输入一条信息,并生成或加入链表,成功返回1,失败返回0

{

static int id=1;

STINFO *head=*stHead,*tail=*stTail,*stNew=NULL;

stNew=(STINFO *)malloc(sizeof(STINFO));

stNew->pType=-1;

stNew->next=NULL;

if(!stNew)//抛出异常

return 0;

stNew->id=id++;

printf("请输入姓名:"),scanf("%9s",stNew->name);

if(getchar()!='
')//抛出异常

return 0;

while(stNew->pType<0 || stNew->pType>1)

printf("请输入职业编号(0:学生,1:教师):"),scanf("%d",&stNew->pType);

switch(stNew->pType)

{

case 0:printf("请输入学生所在班级名称:");

scanf("%9s",stNew->cwInfo.cName);

if(getchar()!='
')//抛出异常

return 0;

break;

case 1:printf("请输入教师的工龄:"),scanf("%d",&stNew->cwInfo.wAge);break;

}

if(head==NULL)

head=(STINFO *)malloc(sizeof(STINFO)),head->next=NULL;

if(head->next==NULL)

head->next=stNew;

else

tail->next=stNew;

tail=stNew;

*stHead=head,*stTail=tail;

return 1;

}



扩展阅读:学编程一年大概多少钱 ... c++和python先学哪个 ... c十十编程要学多久 ... 三类人不适合学编程 ... 初学编程必背50个 ... 编程必背100个代码 ... 编程一般要学多久 ... c++编程适合几岁学 ... 初学电脑入门教程 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网