字符串中出现的每个字符重复存储到新串
程序要求:把在字符串s中出现的每个字符紧随其后重复出现1次,放在一个新串t中,t中字符按原字符串的逆序排列。
例如:当s中的字符串为"12345″时,则t中的字符串应为"5544332211″。
#include <stdio.h>
#include <string.h>
void fun (char s[ ], char t[ ])
{ int i, sl;
sl = strlen(s);
for(i=0;i<s1;i++)
{ t[2*i] = s[sl-i-1];
t[2*i +1] = s[sl-i-1];
}
t[2*sl] = '\0';
}
void main()
{ char s[100], t[100];
printf("\nPlease enter string s:"); scanf("%s", s);
fun(s, t);
printf("The result is: %s\n", t);
}
运行结果
Please enter string s:458762
The result is: 226677885544