#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
#define N 128
int main()
{
int i=,sum;
bool is_exist[N];
char ch;
char str[]; //void *memset(void *s,int ch,size_t n)
//将s所指向的某一块内存中的前n个字节的内容全部设置为ch指定的ASCII值
memset(is_exist,,sizeof(is_exist));
//把用户的每个输入的字符放入str中,直到用户输入了换行停止
while(scanf("%c",&ch)&&ch!='\n'){
//输入的这个字符放在数组中自动转换成对应的ASCII值,更新 is_exist
is_exist[ch]=true;
//把输入的字符存入str这个字符数组
str[i++]=ch;
}
//sum记录的是第一次输入的字符串的长度
sum=i;
//让用户第二次输入字符串
while(scanf("%c",&ch)&&ch!='\n'){
//让is_exist对应的字符的ASCII位标记为false
is_exist[ch]=false;
}
i=;
while(i<sum){
//如果在str[i]的ASCII值做下标 ,在is_exist中不是false,那么是0或者true
//说明这个字符在第二次的输入中没有出现过
if(is_exist[str[i]]!=false)
//输出该字符
printf("%c",str[i]);
i++;
}
return ;
}

总结:1.把字符作为数组的下标会转化为该字符对应的ASCII码。

2.memset函数的使用:void *memset(void *s, int ch, size_t n);

含义:将s所指向的某一块内存中的前n个 字节的内容全部设置为ch指定的ASCII值, 块的大小由第三个参数指定

作用:在一段内存块中填充某个给定的值,它是对较大的结构体数组进行清零操作的一种最快方法

PAT---1050. String Subtraction (20)的更多相关文章

  1. PAT 解题报告 1050. String Subtraction (20)

    1050. String Subtraction (20) Given two strings S1 and S2, S = S1 - S2 is defined to be the remainin ...

  2. PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)

    1050 String Subtraction (20 分)   Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be t ...

  3. pat 1050 String Subtraction(20 分)

    1050 String Subtraction(20 分) Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the ...

  4. PAT 1050 String Subtraction

    1050 String Subtraction (20 分)   Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be t ...

  5. PAT (Advanced Level) 1050. String Subtraction (20)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  6. PAT甲题题解-1050. String Subtraction (20)-水题

    #include <iostream> #include <cstdio> #include <string.h> #include <algorithm&g ...

  7. PAT Advanced 1050 String Subtraction (20 分)

    Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the remaining string after taking ...

  8. PAT Advanced 1050 String Subtraction (20) [Hash散列]

    题目 Given two strings S1 and S2, S = S1 – S2 is defined to be the remaining string afer taking all th ...

  9. PAT练习--1050 String Subtraction (20 分)

    题⽬⼤意:给出两个字符串,在第⼀个字符串中删除第⼆个字符串中出现过的所有字符并输出. 这道题的思路:将哈希表里关于字符串s2的所有字符都置为true,再对s1的每个字符进行判断,若Hash[s1[i] ...

  10. 【PAT甲级】1050 String Subtraction (20 分)

    题意: 输入两个串,长度小于10000,输出第一个串去掉第二个串含有的字符的余串. trick: ascii码为0的是NULL,减去'0','a','A',均会导致可能减成负数. AAAAAccept ...

随机推荐

  1. 黑马程序员-------.net基础知识三

    条件执行语句 if 语句 语法: [csharp] view plaincopyprint? if(条件) { 语句1;语句2:语句3: ··· } 执行过程: 先判断条件是否为true ,如果为tr ...

  2. 【MS Office2013小技巧】Word中公式中的等号对齐

    步骤: 1. 先将所需要对齐的公式分不同行打出来: 2. 选中所有公式,右键点击并选择“对齐点(A) =”,如图 此时,如果能够正常对齐,则无需进行下面的步骤,但如果出现下图情况并未正常对齐的,再进行 ...

  3. 【技术帖】解决 Hudson jenkins 连接等待中 - Waiting for next av

    今天构建项目发现如下问题: jenkins 连接等待中 - Waiting for next available executor 左下角那块一直不运行构建,一直在连接等待. 于是,进入一级页面, 右 ...

  4. tornado异步请求非阻塞

    前言也许有同学很迷惑:tornado不是标榜异步非阻塞解决10K问题的嘛?但是我却发现不是torando不好,而是你用错了 比如最近发现一个事情:某网 前言 也许有同学很迷惑:tornado不是标榜异 ...

  5. 标准MD5加密算法

    标准MD5加密算法: public class Md5 { public static String getMd5(String s) { char hexDigits[] = { '0', '1', ...

  6. 在VS2008中配置WDK7600驱动开发环境

    网上这类资料多如牛毛,也许很多人都是转来转去,却很有人去真正的测试,有时候感觉确实对他人也是一种误导. 这里是我自己在VS2008 + WDK7600.16385.0 + DDKWizard配置自己的 ...

  7. 读书笔记-----Java并发编程实战(二)对象的共享

    public class NoVisibility{ private static boolean ready; private static int number; private static c ...

  8. FishEye简介

    前言     在项目开发过程中,随着开发的进行,将有大量的代码编写提交到代码仓库,如何能全面准确的了解源代码的变化,提交的频率,代码量的趋势,发现代码的缺陷,将是控制源代码质量的重要指标,这个时候一个 ...

  9. 17.1 Replication Configuration 复制配置

    17.1 Replication Configuration 复制配置 17.1.1 How to Set Up Replication 17.1.2 Replication Formats 17.1 ...

  10. easyui datagrid pagesize设置无效