PAT甲级1050 String Subtraction

该博客介绍了PAT甲级1050题——String Subtraction,主要内容是根据给定的两个字符串S1和S2,通过编程计算S1减去S2的结果。题目要求在限制时间内完成操作,输入包括两行,分别表示S1和S2,长度不超过104。博主分享了使用直接模拟方法解决此问题的思路,并提到在C++中遇到的gets()函数导致的编译错误,最终通过改用C语言成功通过测试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目
1050 String Subtraction (20 分)
Given two strings S​1 and S​2 , S=S1−S2 is defined to be the remaining string after taking all the characters in S2 from S​1. Your task is simply to calculate S​1−S​2 for any given strings. However, it might not be that simple to do it fast.

Input Specification:
Each input file contains one test case. Each case consists of two lines which gives S1 and S​2, respectively. The string lengths of both strings are no more than 10​4. It is guaranteed that all the characters are visible ASCII codes and white space, and a new line character signals the end of a string.

Output Specification:
For each test case, print S​1−S​2in one line.

Sample Input:
They are students.
aeiou
Sample Output:
Thy r stdnts.

题目意思
给两个字符串s1,s2,输出s1-s2

思路
直接模拟,需要注意的是字符串范围是10的4次方,其次是gets()函数,一开始用c++交,编译错误,想到可能是gets()的问题就改成c,就过了。

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

char hx[10003];
char a[100003];
int mz[1003]={0};
int main()
{
   
   gets(hx);
   gets(a);
   for(int i=0;i<strlen(a);i++)
       mz[a[i]]=1;
    for(int i=0;i<strlen(hx);i++)
    {
        if(!mz[hx[i]])
        {
            printf("%c",hx[i]);
        }
    }
   return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值