【PTA】字符串正反序连接

将s所指字符串的正序和反序进行连接,形成一个新串放在t所指的数组中。

函数接口定义:

void fun (char  *s, char  *t);

其中st都是用户传入的参数。函数将s所指字符串的正序和反序进行连接,形成一个新串放在t所指的数组中。

裁判测试程序样例:

#include  <stdio.h>
void fun (char  *s, char  *t);
int main()
{  char   s[100], t[100];
  scanf("%s", s);
  fun(s, t);
  printf("The result is: %s\n", t);
  return 0;
}


/* 请在这里填写答案 */

输入样例:

abcd

输出样例:

The result is: abcddcba
void fun (char  *s, char  *t)
{
	int len = 0;
	while(*s != '\0')
	{
		*t = *s;
		s++;
		t++;
		len++;
	}
	s--;
	while(len--)
	{
		*t = *s;
		s--;
		t++;
	}
	 *t = '\0';
}
posted @ 2021-05-10 21:34  ekertree  阅读(744)  评论(0)    收藏  举报