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 ...
随机推荐
- Ionic简介和环境安装
什么是Ionic Ionic是一个用来开发混合手机应用的,开源的,免费的代码库.可以优化html.css和js的性能,构建高效的应用程序,而且还可以用于构建Sass和AngularJS的优化.ioni ...
- 数据结构练习 02-线性结构3. Pop Sequence (25)
Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and p ...
- Automatic Code Generation-->Implement Interface
https://msdn.microsoft.com/en-us/library/hk90416s(v=vs.110).aspx VS中自带的只能提示,一个类继承自某一个接口. 由VS为类生成接口所要 ...
- 利用if else判断几点是什么时间段
static void Main(string[] args) { while (true) { int a; ...
- POJ_2104_Kth_(主席树)
描述 http://poj.org/problem?id=2104 给出一个n个数的数列,m次询问,每次询问求区间[l,r]中第k小的数,无修改操作. K-th Number Time Limit: ...
- ☀【单位】REM
CSS3的REM设置字体大小 支持的浏览器还是蛮多的,比如:Mozilla Firefox 3.6+.Apple Safari 5+.Google Chrome.IE9+和Opera11+.只是可怜的 ...
- GeoServer地图开发解决方案
转自:http://www.cnblogs.com/beniao/archive/2011/01/08/1930822.html GeoServer 是 OpenGIS Web 服务器规范的 J2EE ...
- (转载)c库不正确问题
(转载)http://blog.csdn.net/piratejk/article/details/6115748 在linux下面变成,有时候在一个发行版本上编译通过,并且可以运行,但是将程序拷贝到 ...
- NHibernate加载DLL错误
这几天在开发关于Rest的服务,其中用到了NHibernate来进行数据库交互,突然有一天发现了一个错误,如下: Could not load file or assembly 'NHibernate ...
- Ajax初步实现页面局部内容更替
类似于QQ邮箱的那种局部页面跳转,单页应用常用到,目前很多网页都是这种,但是弊端就是一次加载过多资源,首次加载卡出翔啊