今天考科目三,但是也要抽空学习(手动狗头)
顺便提一下ctype里面的一些好用的东西
有了这些,又可以省一些力气
下面看一道简单的C语言编程题:
随机构造50个句子,使用4个名为article(冠词),noun(名词),verb(动词),preposition(介词)的指向字符串的指针数组。 数组article包含“the”,“a”,“one”,“some”和“any”;数组noun包含“boy”,“girl”,“dog”,“town”和“car”;数组verb包含“drove”,“jumped”,“ran”,“walked”和“skipped”;数组preposition包含“to”,“from”,“over”,“under”和“on“。 程序按如下顺序、随机地从每个数组中挑选一个单词来构造句子:article,noun,verb,preposition,article和noun。每个句子的第一个字母大写,句子以句号结束。
附Y4tacker大佬解答 如下:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<time.h>
int suiji(int *,int *,int *,int *); //这个函数实现随机数的生成
int main()
{
const char* artical[5] ={"the","a","one","some","any"};
const char* noun[5]={"boy","girl","dog","town","car"};
const char* verb[5]={"drove","jumped","ran","walked","skipped"};
const char* preposition[5]={"to","from","over","under","on"};
char final_sentence[50];
int w,z,s,q;
int i;
srand(time(NULL));
for(i=0;i<50;i++)
{
suiji(&w,&z,&s,&q);
strcpy(final_sentence,artical[w]);
strcat(final_sentence," ");
strcat(final_sentence,noun[z]);
strcat(final_sentence," ");
strcat(final_sentence,verb[s]);
strcat(final_sentence," ");
strcat(final_sentence,preposition[q]);
strcat(final_sentence," ");
a = rand() % 5;
n = rand() % 5;
strcat(final_sentence,artical[w]);
strcat(final_sentence," ");
strcat(final_sentence,noun[z]);
strcat(final_sentence,".");
final_sentence[0] = toupper(final_sentence[0]);
puts(final_sentence);
}
}
int suiji(int *w,int *z,int *s,int *q)
{
*w = rand() % 5;
*z = rand() % 5;
*s = rand() % 5;
*q = rand() % 5;
}
?师傅们有什么高强本领可以在评论区指点哦
每天进步,北海虽赊,扶摇可接。
|