Make it Anagram
来源:互联网 发布:php后端开发教程 编辑:程序博客网 时间:2024/06/05 10:13
Problem Statement
Chinese Version
Russian Version
Alice recently started learning about cryptography and found that anagrams are very useful. Two strings are anagrams of each other if they have same character set. For example strings"bacdc"
and "dcbac"
are anagrams, while strings "bacdc"
and "dcbad"
are not.
Alice decides on an encryption scheme involving 2 large strings where encryption is dependent on the minimum number of character deletions required to make the two strings anagrams. She need your help in finding out this number.
Given two strings (they can be of same or different length) help her in finding out the minimum number of character deletions required to make two strings anagrams. Any characters can be deleted from any of the strings.
Input Format
Two lines each containing a string.
Constraints
1 <= Length of A,B <= 10000
A and B will only consist of lowercase latin letter.
Output Format
A single integer which is the number of character deletions.
Sample Input #00:
cdeabc
Sample Output #00:
4
Explanation #00:
We need to delete 4 characters to make both strings anagram i.e. 'd' and 'e' from first string and 'b' and 'a' from second string.
//理解错了题目意思,是可以通过任意变换来成为<span style="color: rgb(57, 66, 78); font-family: 'Whitney SSm A', 'Whitney SSm B', verdana, 'Lucida Grande', sans-serif; font-size: 18px; line-height: 27px;">anagrams</span>
import java.io.*;import java.util.*;import java.text.*;import java.math.*;import java.util.regex.*;public class Solution { public static void op(String s1,String s2){ int n1=s1.length(); int n2=s2.length(); int[] array1=new int[26]; int[] array2=new int[26]; for(int i=0;i<n1;i++){ char c=s1.charAt(i); array1[c-'a']++; } for(int i=0;i<n2;i++){ char c=s2.charAt(i); array2[c-'a']++; } int sum=0; for(int i=0;i<26;i++){ sum+=Math.abs(array1[i]-array2[i]); } System.out.println(sum);} public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner cin=new Scanner(System.in); String a=cin.next(); String b=cin.next(); op(a,b); }}
- Make it Anagram
- make IT different
- Make it easy
- Make it easy
- Make it easysdf
- Make it easysdf
- Make it easysdf
- anagram
- Anagram
- Anagram
- Anagram
- I Can Make It Happen
- 【模拟题】Make it Manhattan
- make a decision & do it at once!
- What It Takes to Make a Student
- What It Takes To Make a Student?
- Life is what we make it!
- finally, i don't make it
- 黑马程序员之 --- 集合
- python常见数据结构
- 预处理程序
- Cordys BOP 4.3平台使用小经验—数据库连接管理、导出流程模型为XPDL
- Windows 远程登录 Linux 服务器
- Make it Anagram
- Android---如何提高模拟器的速度--安装
- GCJ 2015R1B(Noisy Neighbors-分类讨论)
- KMP算法的理解与实现
- 黑马程序员之 ---IO
- android错误集结,慢慢积累
- FTP文件传输协议两种模式-主动模式和被动模式
- 数据库之各种常用数据库连接
- L脚本语言语法手册