字符串处理(c语言)——数据结构_链表

【输入形式】 一个以‘#’为结尾的字符串

【输出形式】 经题中所述规则处理后生成的新字符串

【样例输入】 23s0_d41#

【样例输出】 333_ssss_s_0_\UL_d_11111_1

#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#define OK 1
#define OVERLOW 0
#define LIST_INIT_SIZE 100
typedef struct SqList{
    char *elem;
    int length;
}String;
int InitList_Sq(String *L)
{
    L->elem = (char*)malloc(LIST_INIT_SIZE*sizeof(char));
    if(!L->elem)
        return OVERLOW;
    L->length = 0;
    return OK;
}
int ClearList_Sq(String *L)
{
    if(!L->elem)
        return OVERLOW;
    L->elem = NULL;
    L->length = '0';
    return OK;
}
int ListLength_Sq(String *L)
{
    if(!L->elem)
        return OVERLOW;
    return L->length;
}
void putinto(String *p)
{
    if(p ->length == 0)
        printf("顺序列表为空");
    int i = 0;
    for(i = 0; i < p->length; i++)
    {
        printf("%c", p->elem[i]);
    }
}
void Into(String *p, char x)
{
    p->elem[p->length] = x;
    p->length++;
}
void Swith(char ch, int *s)
{
   *s = (int)ch - 48;
}
void Decide(char ch,String *p, String *q, int i)
{
    int a;
    Swith(ch, &a);
    char s;
    if(a > 0 && a < 9 && i != (p->length - 1))
    {
        s = p->elem[i+1];
        for(i = 0; i < a+1; i++)
        {
            Into(q, s);
        }
        s = '_';
        Into(q, s);
    }
    else
    {
        if(ch == '\\'|| ch == 'U' ||ch == 'L')
        {
            Into(q, ch);
            if(ch == 'L')
            {
                s = '_';
                Into(q, s);
            }
        }
        else
        {
            if(i != (p->length - 1))
            {
                Into(q, ch);
                s = '_';
                Into(q, s);
            }
            else
            {
                Into(q, ch);
            }
        }
    }
}
void Function(String *p, String *q)
{
     int i, a, n;
     for(i = 0; i < p->length; i++)
     {
         Decide(p->elem[i], p ,q ,i );
     }
}
void Cat(char ch[], String *p)
{
    int size = 0;
    size = p->length + strlen(ch);
    p->elem = realloc(p->elem, size);
    strcat(p->elem, ch);
}
int main()
{
    int i, n;
    String *q = (String*)malloc(sizeof(String));
    String *p = (String*)malloc(sizeof(String));
    InitList_Sq(p);
    InitList_Sq(q);
    char arr[100];
    gets(arr);
    n = strlen(arr);
    for(i = 0; i < n; i++)
    {
        if(arr[i] == '#')
            break;
        if(arr[i] == '_')
        {
            Into(q, '\\');
            Into(q,'U');
            Into(q,'L');
            continue;
        }
        Into(q, arr[i]);
    }
    Function(q, p);
    putinto(p);
    return 0;
}





  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

星纪@大梁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值