69,371
社区成员
发帖
与我相关
我的任务
分享
//倒序输出英文语句(不改变单词字母的顺序)
#include <iostream>
using std::cout;
using std::endl;
void reprint(char *s) //倒序打印字符
{
char t[32]={},i=0; //把数组设为空,以便在输出时不至于是乱码。 t[32] = {};表示的具体含义不理解?
int count = 0; //用于记录空格数目
while(*s==' '&&*s) //如果指针s指向地址的值为空且存在,则指针s指向地址的下一位
{
s++;
count++;
}
if(*s=='\0') //如果指针s指向字符床的最后一位(结束符'\0'),则结束函数
return;
while(*s!=' ' && *s) //如果指针指针s指向的值不为空且存在,则把指针s指向的值赋给相应的t[i++]
t[i++]=*s++; //把指针s指向地址的值赋给t[i++]后就立即指向下一位
reprint(s); //递归函数
cout << t;
for(int n = 0; n <= count; n++) //打印出相应的空格数
cout << " ";
}
void reprint_c(char *s) //倒序打印汉字
{
char t[8]={},i=0;
int count = 0;
while(*s==' ' && *s)
{
s++;
count++;
}
if(*s=='\0')
return;
while(*s!=' '&&*s)
t[i++]=*s++;
reprint_c(s);
cout << t << " ";
for(int n = 0; n <= count; n++) //打印出相应的空格数
cout << " ";
}
int main()
{
char *str= " Beijing Changping Tiantongyuan !";
char *str2= " 北京市 昌平区 天通苑 ! ";
reprint(str);
cout << endl;
reprint_c(str2);
cout << endl;
system("pause");
return 0;
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 1000
main()
{
void test(char*, int);
int n;
char a[MAX];
printf ("请输入英语句子:\n");
gets(a);
printf("\n你输入的英文语句是:\n%s\n", a);
n = strlen(a) - 1;
test(a, n);
printf("转换后的英文语句:\n%s\n", a);
system("pause");
}
void test(char *p, int n)
{
int a, b, d, c = 0;
char ch[MAX];
for (a = n, b = n; a >= 0; a--)
{
if (32 <= p[a] && p[a] <= 47)
{
for (d = a +1; d < b; d++)
{
ch[c++] = p[d];
}
ch[c++] = p[a];
b = a;
}
if (a == 0)
{
for (d = a; d < b; d++)
{
ch[c++] = p[d];
}
}
}
ch[c] = '\0';
strcpy(p, ch);
}
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
char words[50][256],symbols[50],dest[256];
int main()
{
char *str="how@are#you?";
char *src=str,*des=dest;
int i=0,widx=0,widx2=0,sidx=0;
for(;*src!='\0'; isalpha(*src) ? (words[widx][widx2++]=*src++) :(widx++,widx2=0,symbols[sidx++]=*src++));
for(i=0;i<widx;i++) for(src=words[widx-i-1];*src!='\0' || (*des++=symbols[i],0);*des++=*src++);
puts(dest);
return 0;
};
void reprint(char *s)//打印字符
{
char t[32]={},i=0,t1[32]={};
while(*s==' '&&*s)
t1[i++]=*s++;
i=0;
if(*s=='\0') return;
while(*s!=' '&&*s)
t[i++]=*s++;
reprint(s);
printf("%s%s",t1,t);
}