第四次试验

#include<iostream>
#include<cstdio>
#include<stdlib.h>
#include<cstring>
#include<string>
using namespace std;

typedef struct Node{
    char data;
    bool flag;
    struct Node *next;
}Node;

string str;

void InitList(Node *&L){
    L=(Node *)malloc(sizeof(Node));
    L->next=NULL;
}

void CreateListR(Node *&L){
    Node *s,*r;
    L=(Node *)malloc(sizeof(Node));
    r=L;
    for(int i=0;i<str.size();i++){
        if(isalpha(str[i])){
            s=(Node *)malloc(sizeof(Node));
            s->data=str[i];
            r->next=s;
            r=s;
        }
    }
    r->next=NULL;
}

void DispList(Node *L,bool f){
    Node *p=L->next;
    while(p!=NULL){
        if(p->flag==f) cout<<p->data<<" ";
        p=p->next;
    }
}

void solve(Node *&L,char c){
    Node *p=L->next;
    while(p!=NULL){
        if(p->data<c) p->flag=true;
        else p->flag=false;
        p=p->next;
    }
}

int main(){
    Node *L;
    char c;
    getline(cin,str);
    CreateListR(L);
    cin>>c;
    //DispList(L);
    solve(L,c);
    DispList(L,true);
    DispList(L,false);
    return 0;
}

#include<iostream>
#include<cstdio>
#include<stdlib.h>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;

typedef struct Node{
    char data;
    struct Node *next;
}Node;

void InitList(Node *&L){
    L=(Node *)malloc(sizeof(Node));
    L->next=NULL;
}

void CreateListR(Node *&L,string ss){
    Node *s,*r;
    L=(Node *)malloc(sizeof(Node));
    r=L;
    for(int i=ss.size()-1;i>=0;i--){
        s=(Node *)malloc(sizeof(Node));
        s->data=ss[i];
        r->next=s;
        r=s;
    }
    r->next=NULL;
}

void DispList(Node *L){
    Node *p=L->next;
    while(p!=NULL){
        cout<<p->data;
        p=p->next;
    }
}

void solve(Node *a1,Node *a2,Node *&ans){
    Node *p1,*p2,*s,*r;
    p1=a1->next;
    p2=a2->next;
    int t=0,num;
    ans=(Node *)malloc(sizeof(Node));
    r=ans;
    while(p1!=NULL&&p2!=NULL){
        int x=p1->data-'0';
        int y=p2->data-'0';
        num=(x+y+t)%10;
        t=(x+y)/10;
        s=(Node *)malloc(sizeof(Node));
        s->data=(char)num+'0';
        //cout<<s->data<<endl;
        r->next=s;
        r=s;
        p1=p1->next;
        p2=p2->next;
    }
    while(p1!=NULL){
        int x=p1->data-'0';
        num=(t+x)%10;
        t=(t+x)/10;
        s=(Node *)malloc(sizeof(Node));
        s->data=(char)num+'0';
        r->next=s;
        r=s;
        p1=p1->next;
    }
    while(p2!=NULL){
        int x=p2->data-'0';
        num=(t+x)%10;
        t=(t+x)/10;
        s=(Node *)malloc(sizeof(Node));
        s->data=(char)num+'0';
        r->next=s;
        r=s;
        p2=p2->next;
    }
    r->next=NULL;
    //DispList(ans);
}

void printans(Node *ans){
    string s="";
    Node *p=ans->next;
    while(p!=NULL){
        s+=p->data;
        p=p->next;
    }
    reverse(s.begin(),s.end());
    cout<<s<<endl;
}

int main(){
    Node *a1,*a2,*ans;
    string s1,s2;
    cin>>s1>>s2;
    CreateListR(a1,s1);
    CreateListR(a2,s2);
    //DispList(a1);
    //DispList(a2);
    solve(a1,a2,ans);
    printans(ans);
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值