PAT---1050. String Subtraction (20)

#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)的更多相关文章
- PAT 解题报告 1050. String Subtraction (20)
1050. String Subtraction (20) Given two strings S1 and S2, S = S1 - S2 is defined to be the remainin ...
- PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)
1050 String Subtraction (20 分) Given two strings S1 and S2, S=S1−S2 is defined to be t ...
- pat 1050 String Subtraction(20 分)
1050 String Subtraction(20 分) Given two strings S1 and S2, S=S1−S2 is defined to be the ...
- PAT 1050 String Subtraction
1050 String Subtraction (20 分) Given two strings S1 and S2, S=S1−S2 is defined to be t ...
- PAT (Advanced Level) 1050. String Subtraction (20)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT甲题题解-1050. String Subtraction (20)-水题
#include <iostream> #include <cstdio> #include <string.h> #include <algorithm&g ...
- PAT Advanced 1050 String Subtraction (20 分)
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking ...
- 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 ...
- PAT练习--1050 String Subtraction (20 分)
题⽬⼤意:给出两个字符串,在第⼀个字符串中删除第⼆个字符串中出现过的所有字符并输出. 这道题的思路:将哈希表里关于字符串s2的所有字符都置为true,再对s1的每个字符进行判断,若Hash[s1[i] ...
- 【PAT甲级】1050 String Subtraction (20 分)
题意: 输入两个串,长度小于10000,输出第一个串去掉第二个串含有的字符的余串. trick: ascii码为0的是NULL,减去'0','a','A',均会导致可能减成负数. AAAAAccept ...
随机推荐
- Maven安装与更新
Maven是Apache组织中的一个颇为成功的开源项目,主要服务于基于Java平 台的项目构建.依赖管理和项目信息管理: 1) Maven是跨平台的,在Windows.Linux和Mac上都可以使用: ...
- 【UVA 1395】 Slim Span (苗条树)
[题意] 求一颗生成树,满足最大边和最小边之差最小 InputThe input consists of multiple datasets, followed by a line containin ...
- Oracle 单实例 2个service的问题
[oracle@PD admin]$ ps -ef | grep smon oracle 1917 1 0 Aug21 ? 00:33:51 ora_smon_podinndb oracle 2265 ...
- How to: Use a Custom User Name and Password Validator
在wcf中使用自定义的用户名和密码验证方式 https://msdn.microsoft.com/en-us/library/aa702565.aspx http://www.codeproject. ...
- Automatic Code Generation-->Implement Interface
https://msdn.microsoft.com/en-us/library/hk90416s(v=vs.110).aspx VS中自带的只能提示,一个类继承自某一个接口. 由VS为类生成接口所要 ...
- Spark大数据处理技术
全球首部全面介绍Spark及Spark生态圈相关技术的技术书籍 俯览未来大局,不失精细剖析,呈现一个现代大数据框架的架构原理和实现细节 透彻讲解Spark原理和架构,以及部署模式.调度框架.存储管理及 ...
- ELK安装配置及nginx日志分析
一.ELK简介1.组成ELK是Elasticsearch.Logstash.Kibana三个开源软件的组合.在实时数据检索和分析场合,三者通常是配合使用,而且又都先后归于 Elastic.co 公司名 ...
- C#入门经典学习笔记一
这篇主要讲C#的一些语法. 1.委托 委托类型声明的格式如下: public delegate void TestDelegate(string message); delegate 关键字用于声明一 ...
- MVC批量导出数据方法
近段时间做了个数据平台,其中涉及到批量导出CSV格式数据的业务,主要使用了部分视图和视图之间传值等知识点,今天做了下整理,特此分享下: 主要分为四步: 1:要打印的数据格式陈列View: 2:自定义导 ...
- Delphi 继承基类的窗体,并显示基类的控件操作。
1. 先建一个普通的窗体,until1 2. 先把类实现基类, 并需要实现基类需要继承的方法, 可以先不用再方法中写实现代码. TForm4 = class(TfrmmtAReportPeriod ...