#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. UISearchBar -- 备忘

    搜索功能的备忘 UISearchBar UISearchBar是一个搜索栏,继承自UIView,也是常用的控件之一,所以特别写一篇备忘方便以后做工具文章. 例子: let searchBar = UI ...

  2. 定位 - MapKit-自定义大头针

    #import <Foundation/Foundation.h> #import <MapKit/MapKit.h> @interface PPAnnotation : NS ...

  3. 关于Java(Hello World程序)

    详解 Hello World 应用程序 源码 class HelloWorldApp { public static void main(String[] args) { System.out.pri ...

  4. 如何有效申请TI的免费样片

     转自如何有效申请TI的免费样片 TI公司愿意为支持中国大学的师生们的教学.实验.创新实践.竞赛和科研项目,提供有限数量的免费样片.首先需要指出的是:所有的样片申请应该是诚实正当的,所有不恰当的申 ...

  5. 【POJ 3167】Cow Patterns (KMP+树状数组)

    Cow Patterns Description A particular subgroup of K (1 <= K <= 25,000) of Farmer John's cows l ...

  6. USB Type-C“三剑客”: 连接器、控制器和电缆

    USB Type-C™是最新的有关电缆布线的USB连接器标准.您会看到,从笔记本电脑.智能手机.闪存到视频系统,这些设备上有一个小型可逆的Type-C连接器.由于Type-C电缆既可以给主机和设备提供 ...

  7. Visual Studio 2015 Update 1 成功安装后运行 “出现未能正确加载[XXXX]包,此问题可能是由配置更改或安装另一个扩展导致的。” 可能的解决方法

    作死装Visual Studio 2015 update 1.安装过程中虽然波澜不惊,但是安装之后运行回报未能正确安装[XXXX]包.找了半天,在stackoverflow中找到了相关的问题,在问题描 ...

  8. WebService调用http://www.webxml.com.cn中的一些服务示例

    1.打开http://www.webxml.com.cn网站下的“全部WebService”,会看到如下图的图片 2.点击打开WSDL连接,如下图,并保存为一个后缀名为wsdl文件,放在项目的根目录下 ...

  9. PEP Index > PEP 339 -- Design of the CPython Compiler 译文

    http://www.python.org/dev/peps/pep-0339/ PEP: 339 标题: CPython的编译器设计 版本: 425fc5598ee8 最后修改: 2011-01-1 ...

  10. 转载:java保留2位小数

    转载:http://blog.csdn.net/wj_j2ee/article/details/8560132 java保留两位小数问题: 方式一: 四舍五入  double   f   =   11 ...