![](https://img-blog.csdnimg.cn/20200516183241156.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Vzc3RtaXJhY2xl,size_16,color_FFFFFF,t_70)
#include <iostream>
#include<cmath>
using namespace std;
int main() {
char arr[] = {"us2ststudent123456789"};
char *out;
char *p =arr;
char a[20]="";
char b[20]="";
int i=0,j=0;
while(*p != '\0')
{
if(*p >= 'a' && *p <= 'z')
{
a[i++]=*p;
}else if(*p >= '0' && *p <= '9')
{
b[j++]=*p;
}else{
cout<<"string is not correct"<<endl;
}
p++;
}
cout<<"a: "<<a<<endl;
cout<<"b: "<<b<<endl;
cout<<"i: "<<i<<endl;
cout<<"j: "<<j<<endl;
int index = 0;
if(abs(i-j)<=1)
{
if(i>j)
{
for(int k=0;k<i;k++)
{
out[index++] = a[k];
index++;
}
index =1;
for(int k=0;k<j;k++)
{
out[index++] = b[k];
index++;
}
}else
{
for(int k=0;k<j;k++)
{
out[index++] = a[k];
index++;
}
index =1;
for(int k=0;k<i;k++)
{
out[index++] = b[k];
index++;
}
}
}else{
cout<<"failed"<<endl;
}
cout <<"out: "<<out << endl;
return 0;
}
a: usststudent
b: 2123456789
i: 11
j: 10
out: u2s1s2t3s4t5u6d7e8n9t
hello https://tool.lu/
sandbox> exited with status 0
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)