用C++的函数写一段代码:输入一串字符,先输出顺向字符,然后输出逆向字符。
答案:5 悬赏:20 手机版
解决时间 2021-02-01 07:10
- 提问者网友:两耳就是菩提
- 2021-01-31 21:10
需要用到 fill_array做补充数组吗,然后还要有show_array做顺向输出,最后是Reverse_array做逆向输出。。。。整个代码要有这3个函数在里面。。。。
最佳答案
- 五星知识达人网友:不如潦草
- 2021-01-31 22:06
//双向链表实现
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
char data;
struct node *next,*prior;
} list;
list *linklist()
{
list *head,*s;
char x;
head=(list*)malloc(sizeof(list));
head->next=head;
head->prior=head;
scanf("%c",&x);
while(x!='\n')
{
s=(list*)malloc(sizeof(list));
s->data=x;
s->prior=head;
s->next=head->next;
head->next->prior=s;
head->next=s;
scanf("%c",&x);
}
return head;
}
int print1(list *h)
{
list *p;
p=h->next;
while(p!=h)
{
printf("%3c",p->data);
p=p->next;
}
printf("\n");
}
int print2(list *h)
{
list *p;
p=h->prior;
while(p!=h)
{
printf("%3c",p->data);
p=p->prior;
}
printf("\n");
}
int main()
{
list *p,*h;
int i;
char x;
h=linklist();
printf("顺序输出\n");
print1(h);
printf("逆序输出\n");
print2(h);
system("pause");
}
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
char data;
struct node *next,*prior;
} list;
list *linklist()
{
list *head,*s;
char x;
head=(list*)malloc(sizeof(list));
head->next=head;
head->prior=head;
scanf("%c",&x);
while(x!='\n')
{
s=(list*)malloc(sizeof(list));
s->data=x;
s->prior=head;
s->next=head->next;
head->next->prior=s;
head->next=s;
scanf("%c",&x);
}
return head;
}
int print1(list *h)
{
list *p;
p=h->next;
while(p!=h)
{
printf("%3c",p->data);
p=p->next;
}
printf("\n");
}
int print2(list *h)
{
list *p;
p=h->prior;
while(p!=h)
{
printf("%3c",p->data);
p=p->prior;
}
printf("\n");
}
int main()
{
list *p,*h;
int i;
char x;
h=linklist();
printf("顺序输出\n");
print1(h);
printf("逆序输出\n");
print2(h);
system("pause");
}
全部回答
- 1楼网友:狂恋
- 2021-02-01 01:30
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char str[100] = {0};
cout << "input a string:";
gets(str);
cout << str << endl;
for(int i = 1; i <= strlen(str); i++)
cout << str[strlen(str)-i];
cout << endl;
return 0;
}简单实现
- 2楼网友:鱼忧
- 2021-02-01 01:08
#include <iostream>
#include<string>
using namespace std;
int main()
{
string s;
cin>>s;
int i;
for(i=s.length()-1;i>=0;i--)
cout<<s[i];
cout<<endl;
return 0;
}
- 3楼网友:逃夭
- 2021-02-01 00:33
ch4 = ch3 - ch2 + ch1 = '0' - '5' + 'a' = 'a' - 5 = 92 = '\'
- 4楼网友:琴狂剑也妄
- 2021-01-31 23:11
太简单的逻辑了,同学要努力啊
#include <iostream.h>
#include <string.h>
int main ()
{
char s[255];
cin.getline(s,255);
cout<<"asc:"<<s<<endl;
cout<<"des:";
for(int i=strlen(s)-1;i>=0;i--)
cout<<s[i];
cout<<endl;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯