字符串减法、ACSII码
AC代码:
普通代码:
import javax.swing.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.nio.file.attribute.AclEntryFlag;
import java.security.AlgorithmConstraints;
import java.sql.Struct;
import java.text.CollationElementIterator;
import java.text.DateFormatSymbols;
import java.util.*;
import java.util.stream.Collectors;public class Main
{static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));static int N = (int)2e5 + 10;static math_myself math_me = new math_myself();static int a[] = new int[N];public static void main(String[] args ) throws IOException{char a[] = rd.nextLine().toCharArray();char b[] = rd.nextLine().toCharArray();StringBuilder s = new StringBuilder("");// 将b数组的字符的ascii码都变成1,打个标记int ascii[] = new int [N];for(int i = 0 ; i < b.length ; i ++){ascii[b[i]] = 1;}// 将ascii码不为1的字符输出,即为A-B的结果for(int i = 0 ; i < a.length ; i ++){if(ascii[a[i]] == 1) continue;else pw.print(a[i]);}pw.println(s);pw.flush();}
}class rd
{static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));static StringTokenizer tokenizer = new StringTokenizer("");static String nextLine() throws IOException { return reader.readLine(); }static String next() throws IOException{while (!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine());return tokenizer.nextToken();}static int nextInt() throws IOException { return Integer.parseInt(next()); }static double nextDouble() throws IOException { return Double.parseDouble(next()); }static long nextLong() throws IOException { return Long.parseLong(next());}static BigInteger nextBigInteger() throws IOException{BigInteger d = new BigInteger(rd.nextLine());return d;}
}class PII
{int x,y;public PII(int x ,int y){this.x = x;this.y = y;}
}class math_myself
{int gcd(int a,int b){if(b == 0) return a;else return gcd(b,a % b);}int lcm(int a,int b){return a * b / gcd(a, b);}// 求n的所有约数List get_factor(int n){List<Long> a = new ArrayList<>();for(long i = 1; i <= Math.sqrt(n) ; i ++){if(n % i == 0){a.add(i);if(i != n / i) a.add(n / i); // // 避免一下的情况:x = 16时,i = 4 ,x / i = 4的情况,这样会加入两种情况 ^-^复杂度能减少多少是多少}}// 相同因子去重,这个方法,完美a = a.stream().distinct().collect(Collectors.toList());// 对因子排序(升序)Collections.sort(a);return a;}// 判断是否是质数boolean check_isPrime(int n){if(n < 2) return false;for(int i = 2 ; i <= n / i; i ++) if (n % i == 0) return false;return true;}
}
加了StringBuilder的代码:(将A和B中不重叠的字符加到一个新的StringBuilder里面去)
import javax.swing.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.nio.file.attribute.AclEntryFlag;
import java.security.AlgorithmConstraints;
import java.sql.Struct;
import java.text.CollationElementIterator;
import java.text.DateFormatSymbols;
import java.util.*;
import java.util.stream.Collectors;public class Main
{static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));static int N = (int)2e5 + 10;static math_myself math_me = new math_myself();static int a[] = new int[N];public static void main(String[] args ) throws IOException{char a[] = rd.nextLine().toCharArray();char b[] = rd.nextLine().toCharArray();StringBuilder s = new StringBuilder("");// 将b数组的字符的ascii码都变成1,打个标记int ascii[] = new int [N];for(int i = 0 ; i < b.length ; i ++){ascii[b[i]] = 1;}// 将ascii码不为1的字符输出,即为A-B的结果for(int i = 0 ; i < a.length ; i ++){if(ascii[a[i]] == 1) continue;else s.append(a[i]);}pw.println(s);pw.flush();}
}class rd
{static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));static StringTokenizer tokenizer = new StringTokenizer("");static String nextLine() throws IOException { return reader.readLine(); }static String next() throws IOException{while (!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine());return tokenizer.nextToken();}static int nextInt() throws IOException { return Integer.parseInt(next()); }static double nextDouble() throws IOException { return Double.parseDouble(next()); }static long nextLong() throws IOException { return Long.parseLong(next());}static BigInteger nextBigInteger() throws IOException{BigInteger d = new BigInteger(rd.nextLine());return d;}
}class PII
{int x,y;public PII(int x ,int y){this.x = x;this.y = y;}
}class math_myself
{int gcd(int a,int b){if(b == 0) return a;else return gcd(b,a % b);}int lcm(int a,int b){return a * b / gcd(a, b);}// 求n的所有约数List get_factor(int n){List<Long> a = new ArrayList<>();for(long i = 1; i <= Math.sqrt(n) ; i ++){if(n % i == 0){a.add(i);if(i != n / i) a.add(n / i); // // 避免一下的情况:x = 16时,i = 4 ,x / i = 4的情况,这样会加入两种情况 ^-^复杂度能减少多少是多少}}// 相同因子去重,这个方法,完美a = a.stream().distinct().collect(Collectors.toList());// 对因子排序(升序)Collections.sort(a);return a;}// 判断是否是质数boolean check_isPrime(int n){if(n < 2) return false;for(int i = 2 ; i <= n / i; i ++) if (n % i == 0) return false;return true;}
}
字符串减法、ACSII码相关推荐
- C#字符串转换为Acsii码,Ascii转化为字符串
1,现在因为遇到一个读取pdf文件文本信息遇到乱么问题,才找到这个文本字符串的编码转换的实现方式来判断是否存在乱码(0>乱码>255): C# 字符转ASCII码,ASCII码转字符 pu ...
- python 语言, 详解fromstring 函数 -------------从字符串到Ascii 码的转换
先来个小例子: test = "abcdef" temp = numpy.fromstring(test,dtype=numpy.int8) print(temp) 结果为:[ 9 ...
- 输入一个字符串,用子函数完成在字符串中找出ACSII码值最大的字符,将其放在第一个位置,并将该字符前的所有字符向后顺序移动
<程序设计基础实训指导教程-c语言> ISBN 978-7-03-032846-5 p143 7.1.2 上级实训内容 [实训内容9]输入一个字符串,用子函数完成在字符串中找出ACSII码 ...
- C语言小算法:ACSII码(多字节)和Unicode(宽字节)互转
C语言小算法:ACSII码(多字节)和Unicode(宽字节)互转 代码: #include <Windows.h> #include <stdio.h> #include & ...
- MATLAB字符串和ASCII码的转换
字符串转ASCII码:abs,如:abs('a');abs('what'); ASCII码转字符串:char,如:char(97);char([97,98,99]);
- 字符串固定长度 易语言_易语言字符串操作源码
易语言字符串操作源码 系统结构:字符串_取长度,字符串_取中间,字符串_取左边,字符串_取右边,字符串_替换,到宽字符,到多字节,取文本数据地址,取字节集数据地址,MultiByteToWideCha ...
- Ruby 对字符串进行转码
Ruby 对字符串进行转码 require 'iconv' input_encoding = "windows-1252" output_encoding = 'utf-8' co ...
- python 字符串与ASCII码转换的脚本
这里写自定义目录标题 #!/usr/bin/python coding=utf-8flag = 1 while flag:print(">>=================== ...
- python字符串按ascii码排序_C# 字符串按 ASCII码 排序的方法
在和银行做数据对接时,涉及到数据传输时的验签及加密.其中数据签名方案中就要求数据项根据属性名按 ASCII码 进行升序排序.C#中的ASCII码排序并不是表面上那么简单,一不小心就入坑了.因为C#的排 ...
- Redis源码-String:Redis String命令、Redis String存储原理、Redis String三种编码类型、Redis字符串SDS源码解析、Redis String应用场景
Redis源码-String:Redis String命令.Redis String存储原理.Redis String三种编码类型.Redis字符串SDS源码解析.Redis String应用场景 R ...
最新文章
- 对h.264压缩视频码流中i帧的提取(firstime)
- 熟悉MyEclipse
- 云图说|初识ModelArts开发者生态社区——AI Gallery
- csharp语言_电脑绝技教你22天学精Csharp之第五天
- 微信小程序做留言板mysql_微信小程序实现留言板(Storage)
- 现代操作系统(原书第四版)课后题答案 —— 第二章 进程与线程
- mysql复制表结构并创建新表_mysql ---复制表结构---创建新表
- 【CVPR2022】论文列表与下载——PartThree
- 【中国数据创新琅琊榜】萨纳斯大数据实验室,高校大数据教学、实训、人才培养的最佳选择!
- 太强!拿下腾讯公司技术突破奖,腾讯云 RTC 实时音视频技术到底了有多牛?...
- Mac下的平铺式桌面 - Yabai
- 在VS2017中添加WTL窗口
- 用Interl 5100AGN 无线网卡破解无线网络WEP密码
- 微信小程序 - “本地资源图片无法通过WXSS 获取,可以使用网络图片,或者 base64,或者使用标签” 解决
- Bulma的简单使用
- 20个必不可少的Python库也是基本的第三方库
- 递归、迭代和分治(1):递归
- Excel如何快速小计求和
- 区块链技术如何赋能医学成像?
- zookeeper zkCli.sh的基本使用方法