//#include "stdafx.h"//If the vc++6.0, with this line.
#include
using namespace std;
char *fun(char *str){
int i,j;
for(j=0;str[j];j++);
--j = j&1 ? j : j-1;
for(i=1;istr[i]^=str[j],str[j]^=str[i],str[i]^=str[j];
return str;
}
int main(int argc,char *argv[]){
char s[]="ggoi romndno";
cout << fun(s) << endl;
return 0;
}
运行结果:
#include
int main()
{int i,j;
char c,s[200];
gets(s);
for(j=0;s[j];j++);
if(j%2==0)j--;
for(i=1;i{c=s[i]; s[i]=s[j]; s[j]=c;}
printf("%s\n",s);
return 0;
}
#include
using namespace std;
int search(int* p1, int n, int* p2);
void print(int* p, int n);
int main()
{
int arr1[10] = {1,2,3,4,5,6,7,8,9,10};
int arr2[] = { 0 };
int count = search(arr1, 10, arr2);
print(arr1, 10);
print(arr2, count);
system("pause");
}
int search(int* p1, int n, int* p2)
{
int result = 0;
for (int i = 0; i < n; i++)
{
if (p1[i] % 2 != 0)
{
p2[result] = p1[i];
result++;
}
}
return result;
}
void print(int* p, int n)
{
for (int i = 0; i < n; i++)
{
cout << p[i];
}
cout << endl;
}
看了接口有返回值,就不敢直接动输入
用了复制和内存释放,然而我想多了...
#include
char *fun(char *str){
int i,len=strlen(str);
char *text=(char*)malloc(sizeof(char)*(len+1));
text[len]='\0';
if(len%2==1){
len--;text[len]=str[len];
}
for(i=0;itext[i]=i%2==0? str[i] : str[len-i];
return text;
};
int main(){
char str[]="ggoi romndno";
char *text=fun(str);
printf("%s => %s",str,text);
free(text);
return 0;
}
ggoi romndno => good morning
Process returned 0 (0x0) execution time : 0.019 s
Press any key to continue.
手机下51自学网app!里面可以看到C++,或者java和其他语言方面的教学视频。