C语言每个句子的每一个单词 倒置
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/10 15:25:00
C语言每个句子的每一个单词 倒置
给出一个句子,把每一个字母倒置,但不改变单词的顺序.
输入:
这个题有多个CASE.第一行给出一个正整数N(N
给出一个句子,把每一个字母倒置,但不改变单词的顺序.
输入:
这个题有多个CASE.第一行给出一个正整数N(N
#include
#include
#define MAXBLOCKS 499 // 块数目上限
#define MAXSENSIZE 300 // 句子长度上限
#define INITSENSIZE 600 // 句子池初始容量
#define INCRESENSIZE 400 // 句子池渐增容量
/* 仓库 */
typedef struct
{
int count; // 块数目(count=nSize;
lpStorage->blocksize=(int *)malloc(sizeof(int) * nSize);
lpStorage->sentence=(char *)malloc(sizeof(char) * INITSENSIZE);
lpStorage->sentencesize=INITSENSIZE;
lpStorage->sentenceused=0;
if(!lpStorage->blocksize || !lpStorage->sentence)
{
DestroyStorage(lpStorage);
return 0;
}
else
{
return 1;
}
}
int DestroyStorage(STORAGE *lpStorage)
{
if(!lpStorage)
return 0;
lpStorage->count=0;
lpStorage->sentencesize=0;
lpStorage->sentenceused=0;
free(lpStorage->blocksize);
free(lpStorage->sentence);
lpStorage->blocksize=NULL;
lpStorage->sentence=NULL;
return 1;
}
int EnlargeStorage(STORAGE *lpStorage)
{
char *newptr;
if(!lpStorage)
return 0;
newptr=(char *)realloc(lpStorage->sentence,sizeof(char) \
* (lpStorage->sentencesize+INCRESENSIZE));
if(!newptr)
return 0;
lpStorage->sentence=newptr;
lpStorage->sentencesize +=INCRESENSIZE;
return 1;
}
int InputStorage(STORAGE *lpStorage)
{
int i,j;
char *start,*end;
if(!lpStorage)
return 0;
for(i=0;icount;++i)
{
scanf(" %d",lpStorage->blocksize+i);
if(lpStorage->blocksize[i]sentencesize-lpStorage->sentenceused) < (MAXSENSIZE+2))
{
if(!EnlargeStorage(lpStorage))
return 0;
}
start=fgets(lpStorage->sentence+lpStorage->sentenceused,MAXSENSIZE,stdin);
if(!start)
return 0;
for(end=start;*end;++end)
{
if(*end=='\n')
{
lpStorage->sentenceused +=end-start+1;
*end='\0';
ReverseString(start);
}
}
}
}
return 1;
}
int ReverseString(char *str)
{
char c;
char *start,*end;
if(!str)
return 0;
do
{
start=str;
while(*start==' ' || !*start)
{
if(!*start)
return 1;
++start;
}
end=start;
while(*end!=' ' && *end)
{
++end;
}
str=end;
--end;
while(startsentence;
for(i=0;icount;++i)
{
puts("");
for(j=0;jblocksize[i];++j)
{
puts(str);
while(*str++)
;
}
}
return 1;
}
int StartWork(void)
{
int count;
STORAGE stStorage;
scanf(" %d",&count);
if(countMAXBLOCKS)
return 0;
if(!InitStorage(&stStorage,count))
return 0;
if(!InputStorage(&stStorage))
return 0;
if(!ShowStorage(&stStorage))
return 0;
if(!DestroyStorage(&stStorage))
return 0;
return 1;
}
#include
#define MAXBLOCKS 499 // 块数目上限
#define MAXSENSIZE 300 // 句子长度上限
#define INITSENSIZE 600 // 句子池初始容量
#define INCRESENSIZE 400 // 句子池渐增容量
/* 仓库 */
typedef struct
{
int count; // 块数目(count=nSize;
lpStorage->blocksize=(int *)malloc(sizeof(int) * nSize);
lpStorage->sentence=(char *)malloc(sizeof(char) * INITSENSIZE);
lpStorage->sentencesize=INITSENSIZE;
lpStorage->sentenceused=0;
if(!lpStorage->blocksize || !lpStorage->sentence)
{
DestroyStorage(lpStorage);
return 0;
}
else
{
return 1;
}
}
int DestroyStorage(STORAGE *lpStorage)
{
if(!lpStorage)
return 0;
lpStorage->count=0;
lpStorage->sentencesize=0;
lpStorage->sentenceused=0;
free(lpStorage->blocksize);
free(lpStorage->sentence);
lpStorage->blocksize=NULL;
lpStorage->sentence=NULL;
return 1;
}
int EnlargeStorage(STORAGE *lpStorage)
{
char *newptr;
if(!lpStorage)
return 0;
newptr=(char *)realloc(lpStorage->sentence,sizeof(char) \
* (lpStorage->sentencesize+INCRESENSIZE));
if(!newptr)
return 0;
lpStorage->sentence=newptr;
lpStorage->sentencesize +=INCRESENSIZE;
return 1;
}
int InputStorage(STORAGE *lpStorage)
{
int i,j;
char *start,*end;
if(!lpStorage)
return 0;
for(i=0;icount;++i)
{
scanf(" %d",lpStorage->blocksize+i);
if(lpStorage->blocksize[i]sentencesize-lpStorage->sentenceused) < (MAXSENSIZE+2))
{
if(!EnlargeStorage(lpStorage))
return 0;
}
start=fgets(lpStorage->sentence+lpStorage->sentenceused,MAXSENSIZE,stdin);
if(!start)
return 0;
for(end=start;*end;++end)
{
if(*end=='\n')
{
lpStorage->sentenceused +=end-start+1;
*end='\0';
ReverseString(start);
}
}
}
}
return 1;
}
int ReverseString(char *str)
{
char c;
char *start,*end;
if(!str)
return 0;
do
{
start=str;
while(*start==' ' || !*start)
{
if(!*start)
return 1;
++start;
}
end=start;
while(*end!=' ' && *end)
{
++end;
}
str=end;
--end;
while(startsentence;
for(i=0;icount;++i)
{
puts("");
for(j=0;jblocksize[i];++j)
{
puts(str);
while(*str++)
;
}
}
return 1;
}
int StartWork(void)
{
int count;
STORAGE stStorage;
scanf(" %d",&count);
if(countMAXBLOCKS)
return 0;
if(!InitStorage(&stStorage,count))
return 0;
if(!InputStorage(&stStorage))
return 0;
if(!ShowStorage(&stStorage))
return 0;
if(!DestroyStorage(&stStorage))
return 0;
return 1;
}
C语言:输入一个英文句子,要求将每个单词的第一个字母删除.
C语言问题 输入一个英文句子,将每个单词的第一个字母改成大写字母
C语言求助:输入一个英文句子,将每个单词的第一个字母改成大写字母.
(C语言编程)输入一个英文句子,将每个英文单词的头字母变为大写,单词之间用空格隔开
C语言打印每个数的平方
C语言 :编写 一个程序使一个2行3列的矩阵倒置成3行俩列的矩阵.就是矩阵的倒置、 谢谢拉 .
C语言编程求一个英文句子中的单词数和最长单词的位置、长度及输出这个单词.
爱问C语言——矩阵倒置.
c语言 写一个函数,找出一个英文句子中最长的单词
提取英文句子中的单词并排序输出 c语言
输入英文句子统计单词个数c语言
基础c语言问题:要求输入任意单词,输出单词的每个字母后的第三个字母.例如输入yeah,则输出bhdk