|
发表于 2023-7-22 21:56:01
|
显示全部楼层
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
void move(char a[], int len)
{
int i, j;
char c;
for (i = 0; i < len; i++)
{
if (isdigit(a[i]) && isdigit(a[i + 1]))
{
c = a[i];
a[i] = a[i + 1];
a[i + 1] = c;
}
}
}
int main()
{
char a[] = "This5. is Dev-C++ 11";
int len = strlen(a);
move(a, len);
puts(a);
return 0;
}
/**********Program**********/
void move(char a[], int len)
{
int i, j;
char c;
for (i = 0; i < len; i++)
{
if (isdigit(a[i]) && isdigit(a[i + 1]))
{
c = a[i];
a[i] = a[i + 1];
a[i + 1] = c;
}
}
}
/********** End **********/
这个程序通过遍历字符串,找到连续的两个数字字符,然后将它们交换位置。在主函数中,我们调用了move()函数来处理字符串a[]。在move()函数中,我们使用了两个指针i和j来追踪当前位置和交换位置。当发现连续的两个数字字符时,我们交换它们的位置,即将a[i]和a[i+1]的值进行交换。最终,我们会得到处理后的字符串并将其打印输出。 |
|