字符串练习
作者:互联网
进阶:空间复杂度 O(n)O(n) , 时间复杂度 O(n)O(n)
#define isup(x) (((x)>=('A'))&&((x)<=('Z')))
#define islitter(x) (((x)>=('a'))&&((x)<=('z')))
#define up2liter(x) ((x)=((x)+('a'-'A')))
#define liter2up(x) ((x)=((x)-('a'-'A')))
char* trans(char* s, int n ) {
char* p = malloc(n*sizeof(char));
char *plen,*ptmp = s,*pout;
int len = 0,wordposi[100001];
long int wordnum = 1;
for(plen=s;*plen;plen++)
{
len++;
if(*plen == ' ')
{
wordposi[wordnum++] = len;
}
}
pout = p;
ptmp[len] = ' ';
wordposi[0] = 0;
for(int i = wordnum-1;i>=0;i--)
{
while((ptmp[wordposi[i]]) !=' ')
{
*p = ptmp[wordposi[i]];
wordposi[i]++;
p++;
}
*p = ' ';
p++;
}
p = pout;
while(*p)
{
if(isup(*p)) up2liter(*p);
else if(islitter(*p)) liter2up(*p);
else{}
p++;
}
pout[len]='\0';
return pout;
}
标签:wordposi,++,练习,len,char,pout,字符串,plen 来源: https://www.cnblogs.com/dearrusunflower/p/16215504.html