题目:字符串换
分析:略
注意:不同类型 分开讨论。当把 非字母字符 当作单词分隔标志时,用另一个变量 作为单词在数组里的位置下标。
参考其他博主:
https://blog.youkuaiyun.com/kingsraywii/article/details/23848063
TLE 代码
#include"stdlib.h"
#include"stdio.h"
#include"string.h"
#include"math.h"
#include"stdlib.h"
#include"stdio.h"
#include"string.h"
#include"math.h"
int yuanyin(char a);
int main()
{
char a[1000005],temp[1005]={0},temp1[2]={0};
int k=0,i=0;
while(gets(a)!=NULL)
{
for(i=0; i<strlen(a); i++)
{
if((a[i]>='a'&&a[i]<='z') || (a[i]>='A'&&a[i]<='Z'))
{
temp[k++]=a[i];
}
else
{
if(temp[0]!=0 )
{
if(yuanyin(temp[0]))
{
strcat(temp,"ay");
printf("%s",temp); k=0;memset(temp,0,sizeof(temp));
}
else
{
temp1[0]=temp[0];
strcat(temp,temp1);
strcat(temp,"ay");
printf("%s",temp+1); k=0;memset(temp,0,sizeof(temp));
}
}
printf("%c",a[i]);
}
}
if(temp[0]!=0 )
{
if(yuanyin(temp[0]))
{
strcat(temp,"ay");
printf("%s",temp); k=0;memset(temp,0,sizeof(temp));
}
else
{
temp1[0]=temp[0];
strcat(temp,temp1);
strcat(temp,"ay");
printf("%s",temp+1); k=0;memset(temp,0,sizeof(temp));
}
}
printf("\n");
}
return 0;
}
int yuanyin(char a)
{
if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u'||a=='A'||a=='E'||a=='I'||a=='O'||a=='U')
return 1;
else
return 0;
}
修改后
#include"stdlib.h"
#include"stdio.h"
#include"string.h"
int yuanyin(char a);
int main()
{
char a[1000005],temp[1000005]= {0};
int k=0,i=0;
while(gets(a)!=NULL)
{
for(i=0; i<strlen(a); i++)
{
if((a[i]>='a'&&a[i]<='z') || (a[i]>='A'&&a[i]<='Z'))
{
temp[k++]=a[i];
}
else
{
temp[k]=0;
if(temp[0]!=0 )
{
if(yuanyin(temp[0]))
{
printf("%say",temp);
k=0;
}
else
{
printf("%s%cay",temp+1,temp[0]);
k=0;
}
}
printf("%c",a[i]);
}
}
temp[k]=0;
if(temp[0]!=0 )
{
if(yuanyin(temp[0]))
{
printf("%say",temp);
k=0;
}
else
{
printf("%s%cay",temp+1,temp[0]);
k=0;
}
}
printf("\n");
}
return 0;
}
int yuanyin(char a)
{
if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u'||a=='A'||a=='E'||a=='I'||a=='O'||a=='U')
return 1;
else
return 0;
}
修改后仍各种错误。TLE,WA,PE,CE都来了一遍,有谁知道问题在哪?