xmu 1425.字符串的增添

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    char str[2002],ch,s[10];
    scanf("%s",str);
    int len,n,i,j;
    len=strlen(str);
    scanf("%d",&n);
    while(n)
    {
        n--;
        scanf("%s",s);
        if(s[0]=='d')
        {
            scanf("%d",&i);
            for(j=i-1; j<len-1; j++)
                str[j]=str[j+1];
            len--;
        }
        else
        {
            scanf("%d %c",&i,&ch);
            if(len==1&&i==1)//注意一个字符的情况
            {
                str[i]=str[0];
                str[0]=ch;
            }
            else
            {
                for(j=len-1; j>=i-1; j--)
                {
                    str[j+1]=str[j];
                }
                str[i-1]=ch;
            }
            len++;
        }
    }
    for(i=0; i<len; i++)
        printf("%c",str[i]);
    printf("\n");
    return 0;
}

你可能感兴趣的:(xmu 1425.字符串的增添)