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 ...
随机推荐
- STM32之DMA
一.DMA简介 1.DMA简介 DMA(Direct Memory Access:直接内存存取)是一种可以大大减轻CPU工作量的数据转移方式. CPU有转移数据.计算.控制程序转移等很多功能,但其实转 ...
- linq 动态排序
/// <summary> /// 排序 /// </summary> /// <typeparam name="T"></typepar ...
- leetcode其余题目
1.Largest Rectangle in Histogram http://discuss.leetcode.com/questions/259/largest-rectangle-in-hist ...
- redis基本命令的演示:
import redis r = redis.Redis(host='127.0.0.1', port=6379,db = 0) #查看匹配redis的数据 r.keys() #查看redis的大小 ...
- 【网络流24题】No.1 搭配飞行员(飞行员配对方案问题)
[问题描述] 飞行大队有若干个来自各地的驾驶员,专门驾驶一种型号的飞机,这种飞机每架有两个驾驶员,需一个正驾驶员和一个副驾驶员.由于种种原因,例如相互配合的问题,有些驾驶员不能在同一架飞机上飞 ...
- 【BZOJ 3529】 [Sdoi2014]数表 (莫比乌斯+分块+离线+树状数组)
3529: [Sdoi2014]数表 Description 有一张N×m的数表,其第i行第j列(1 < =i < =礼,1 < =j < =m)的数值为能同时整除i和j的所有 ...
- 标准MD5加密算法
标准MD5加密算法: public class Md5 { public static String getMd5(String s) { char hexDigits[] = { '0', '1', ...
- HDU 3308 LCIS 线段树区间更新
最近开始线段树一段时间了,也发现了不少大牛的博客比如HH大牛 ,小媛姐.这个题目是我在看HH大牛的线段树专题是给出的习题,(可以去他博客找找,真心推荐)原本例题是POJ3667 Hotel 这个题目 ...
- 编写优质嵌入式C程序
前言:这是一年前我为公司内部写的一个文档,旨在向年轻的嵌入式软件工程师们介绍如何在裸机环境下编写优质嵌入式C程序.感觉是有一定的参考价值,所以拿出来分享,抛砖引玉. 转载请注明出处:http://bl ...
- 【CF】310 Div.1 C. Case of Chocolate
线段树的简单题目,做一个离散化,O(lgn)可以找到id.RE了一晚上,额,后来找到了原因. /* 555C */ #include <iostream> #include <str ...