UVa468 - Key to Success(水题)

 Key to Success 

Any one-to-one mapping, f, of any alphabet to itself can be used to encode text by replacing each occurrence of any letter, c, with f(c). One such mapping could be the mapping of a letter to three positions beyond the letter in the alphabet. That is, tex2html_wrap_inline35 , tex2html_wrap_inline37 , tex2html_wrap_inline39 , tex2html_wrap_inline41 and so on.

With this mapping, ``The car is blue'' will be encoded as ``Wkh fdu lv eoxh''.

Input and Output

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

Your correct program should decodes the contents of each input set according to the following guidelines:

  1. Only letters are encoded. Letters are mapped to letters. Uppercase letters are different from their lowercase counter parts.
  2. The mapping that defines the encoding is one-to-one. That is, two different letters never map to the same letter of the alphabet ( tex2html_wrap_inline43 and tex2html_wrap_inline45 is impossible).
  3. There are two input lines - the first one contains a text (not encoded) and the second one contains an encoded text. This text is to be decoded by your program.
  4. Both lines are written by the same person.
  5. It is to be assumed that any person uses letters of the alphabet with the same RELATIVE FREQUENCYfrom document to document and no two letters are used with the same frequency. That is, the most frequently used letter in the first line maps to the most frequently used letter in the second one; the second most frequently used letter maps to the second most frequently used letter and so on.

 The outputs of two consecutive cases will be separated by a blank line.

Sample Intput

1

abacxbacac
qqqqqrrrrssstt

Sample Output

aaaaaccccbbbxx
import java.io.FileInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.OutputStreamWriter;
import java.io.StreamTokenizer;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.util.TreeMap;

public class Main {
	public static final boolean DEBUG = false;
	public static final int N = 100000;
	public BufferedReader cin;
	public PrintWriter cout;
	// public StreamTokenizer tokenizer;
	public StringTokenizer tokenizer;
	public String s, t;


	public void init() {
		try {
			if (DEBUG) {
				cin = new BufferedReader(new InputStreamReader(
						new FileInputStream("e:\\uva_in.txt")));
			} else {
				cin = new BufferedReader(new InputStreamReader(System.in));
			}

			// tokenizer = new StreamTokenizer(cin);
			cout = new PrintWriter(new OutputStreamWriter(System.out));
			tokenizer = new StringTokenizer("");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String next() {
		try {
			/*
			 * tokenizer.nextToken(); if (tokenizer.ttype ==
			 * StreamTokenizer.TT_EOF) return null; else if (tokenizer.ttype ==
			 * StreamTokenizer.TT_NUMBER) { return
			 * String.valueOf((int)tokenizer.nval); } else return
			 * tokenizer.sval;
			 */

			while (!tokenizer.hasMoreTokens()) {
				String s = cin.readLine();
				// System.out.println("s:" + s + " " + (s == null));
				if (s == null)
					return null;
				tokenizer = new StringTokenizer(s);
			}

			return tokenizer.nextToken();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public boolean input() {
		// next();
		s = next();
		t = next();
		//System.out.println("s:" + s + " t:" + t);
		return true;
	}

	public void solve(int cas) {
		TreeMap<Character, Integer> srcHash = new TreeMap<Character, Integer>();
		TreeMap<Character, Integer> dstHash = new TreeMap<Character, Integer>();

		for (int i = 0, len = s.length(); i < len; i++) {
			char ch = s.charAt(i);
			if (Character.isLetter(ch)) {
				if (srcHash.containsKey(ch)) {
					int cnt = srcHash.get(ch);
					srcHash.put(ch, cnt + 1);
				} else {
					srcHash.put(ch, 1);
				}
			}
		}

		for (int i = 0, len = t.length(); i < len; i++) {
			char ch = t.charAt(i);
			if (Character.isLetter(ch)) {
				if (dstHash.containsKey(ch)) {
					int cnt = dstHash.get(ch);
					dstHash.put(ch, cnt + 1);
				} else {
					dstHash.put(ch, 1);
				}
			}
		}

		TreeMap<Integer, Character> a = new TreeMap<Integer, Character>();
		TreeMap<Integer, Character> b = new TreeMap<Integer, Character>();
		HashMap<Character, Character> ansMap = new HashMap<Character, Character>();
		Iterator<Map.Entry<Character, Integer>> it1 = srcHash.entrySet().iterator();
		Iterator<Map.Entry<Character, Integer>> it2 = dstHash.entrySet().iterator();
		Iterator<Map.Entry<Integer, Character>> ait = a.entrySet().iterator();
		Iterator<Map.Entry<Integer, Character>> bit = b.entrySet().iterator();
		
		while (it1.hasNext()) {
			Map.Entry<Character, Integer> entry = it1.next();
			char ch1 = entry.getKey();
			int ch2 = entry.getValue();
			//System.out.println("c:" + ch1 + " cnt:" + ch2);
			a.put(ch2, ch1);
		}

		while (it2.hasNext()) {
			Map.Entry<Character, Integer> entry = it2.next();
			char ch1 = entry.getKey();
			int ch2 = entry.getValue();
			b.put(ch2,  ch1);
		}

		ait = a.entrySet().iterator();
		bit = b.entrySet().iterator();
		while (ait.hasNext()) {
			char ch1 = ait.next().getValue();
			char ch2 = bit.next().getValue();
			ansMap.put(ch2, ch1);
		}
		
		StringBuffer sb = new StringBuffer();
		for (int i = 0, len = t.length(); i < len; i++) {
			char ch = t.charAt(i);
			if (Character.isLetter(ch)) {
				sb.append(ansMap.get(ch));
			} else sb.append(ch);
		}

		cout.println(sb.toString());
		if (cas  != 0) cout.println();
		cout.flush();
	}

	public static void main(String[] args) {
		Main solver = new Main();
		solver.init();

		int t = Integer.parseInt(solver.next());
		while (t-- > 0) {
			solver.input();
			solver.solve(t);
		}
	}
}


 

 

基于Spring Boot搭建的一个多功能在线学习系统的实现细节。系统分为管理员和用户两个主要模块。管理员负责视频、文件和文章资料的管理以及系统运营维护;用户则可以进行视频播放、资料下载、参与学习论坛并享受个性化学习服务。文中重点探讨了文件下载的安全性和性能优化(如使用Resource对象避免内存溢出),积分排行榜的高效实现(采用Redis Sorted Set结构),敏感词过滤机制(利用DFA算法构建内存过滤树)以及视频播放的浏览器兼容性解决方案(通过FFmpeg调整MOOV原子位置)。此外,还提到了权限管理方面自定义动态加载器的应用,提高了系统的灵活性和易用性。 适合人群:对Spring Boot有一定了解,希望深入理解其实际应用的技术人员,尤其是从事在线教育平台开发的相关从业者。 使用场景及目标:适用于需要快速搭建稳定高效的在线学习平台的企业或团队。目标在于提供一套完整的解决方案,涵盖从资源管理到用户体验优化等多个方面,帮助开发者更好地理解和掌握Spring Boot框架的实际运用技巧。 其他说明:文中不仅提供了具体的代码示例和技术思路,还分享了许多实践经验教训,对于提高项目质量有着重要的指导意义。同时强调了安全性、性能优化等方面的重要性,确保系统能够应对大规模用户的并发访问需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kgduu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值