Sicily 2370. Just The Simple Fax
来源:互联网 发布:金域名都南昌 编辑:程序博客网 时间:2024/06/05 08:21
2370. Just The Simple Fax
Constraints
Time Limit: 1 secs, Memory Limit: 256 MB
Description
Input
The first line of input contains a single integer P, (1P1000), which is the number of data sets that follow. Each data set consists of multiple lines. The first line contains two (2) decimal integer values: the problem number, followed by a space, followed by the number of bytes B, (1B5000), to encode. The remaining line(s) contain(s) the data to be encoded. Each line of data to encode will contain 80 hexadecimal digits (except the last line, which may contain less). 2 hexadecimal digits are used to represent each byte. Hexadecimal digits are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
Output
For each data set, there are multiple lines of output. The first line contains a decimal integer giving the data set number followed by a single space, followed by a decimal integer giving the total number of encoded bytes. The remaining lines contain the encoded data each with 80 hexadecimal digits, except the last, which may contain less.
Sample Input
4 1 1 07 2 5 F4A5A5A5A5 3 44 0000000000000000FFFFFF66665A5A5A5A5A71727374758008011011135555555555555501020399 777777CC 4 40 68686868686868686868686868686868686868686868686868686868686868686868686868686868
Sample Output
1 2 0007 2 4 00F481A5 3 32 850080FF016666825A0A717273747580080110111384550301020399807700CC 4 2 A568
Problem Source
每周一赛第一场
// Problem#: 2370// Submission#: 3375194// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include <stdio.h>#include <iostream>#include <vector>#include <string>#include <stack>#include <iomanip>#include <algorithm>#include <queue>#include <functional>#include <map>#include <string.h>#include <math.h>using namespace std;string text;string ans;char h[17] = "0123456789ABCDEF";string alone;int aloneNum;void checkAlone() { if (alone != "") { int shang = aloneNum / 128; int yu = aloneNum % 128; int k = 0; while (shang--) { ans += "7F"; for (int k = 0; k < 128 * 2; k++) { ans.push_back(alone[k]); } alone = alone.substr(2 * 128, alone.size() - 2 * 128); } if (yu) { yu--; char c2 = h[yu % 16]; yu /= 16; char c1 = h[yu % 16]; ans.push_back(c1); ans.push_back(c2); ans += alone; } aloneNum = 0; alone = ""; }}int main() { std::ios::sync_with_stdio(false); int caseNum; cin >> caseNum; while (caseNum--) { int counter, N; cin >> counter >> N; N *= 2; for (int i = 0; i < N / 80 + (N % 80 ? 1 : 0); i++) { string temp; cin >> temp; text += temp; } int s = text.size(); ans = ""; for (int i = 0; i < s; ) { int j, num = 1; for (j = i + 2; j < s && text[j] == text[j - 2] && text[j + 1] == text[j - 1]; j += 2) { num++; } if (num == 1) { aloneNum++; alone += text.substr(i, 2); } else if (num == 2) { aloneNum += 2; alone += text.substr(i, 2) + text.substr(i, 2); } else { checkAlone(); int shang = num / 130; int yu = num % 130; while (shang--) { ans += "FF" + text.substr(i, 2); } if (yu) { if (yu < 3) { aloneNum += yu; while (yu--) alone += text.substr(i, 2); } else { yu -= 3; char c2 = h[yu % 16]; yu /= 16; yu += 8; char c1 = h[yu % 16]; ans.push_back(c1); ans.push_back(c2); ans += text.substr(i, 2); } } } i = j; } checkAlone(); cout << counter << " " << ans.size() / 2 << endl; for (int i = 0, j = 0; i < ans.size(); i++) { cout << ans[i]; j++; if (j == 80) { cout << endl; j = 0; } } if (ans.size() % 80) cout << endl; text.clear(); ans.clear(); } return 0;}
- Sicily 2370. Just The Simple Fax
- 【soj 2370】Just The Simple Fax( http://soj.me/show_problem.php?pid=2370)
- Sicily 2371. Show Me The Fax
- fax
- FAX
- sicily 1775. Simple Sort
- Sicily 3392. Simple Calculation
- sicily--1775. Simple Sort
- sicily 1107. Simple Puzzle
- Just a simple case about the oracle 11gR1 dataguard configuration
- Sicily 1775. Simple Sort Description
- zoj1222 Just the Facts
- Just The last
- 1199: Just the Facts
- The Just-World Fallacy
- Just the Facts(P1604)
- Just face the code!
- 568 - Just the Facts
- uncognizable insn
- 遇到没有exe文件的驱动
- linux网络系统安全防范措施
- 拿到一个代码,如何快速分析项目结构与各函数关系?
- Django代码注意
- Sicily 2370. Just The Simple Fax
- listview中添加Button后item不能点击的解决办法
- mac 下更新sdk
- PLSQL collection 方法 和 三种collection对比
- Sicily 4959. Hidden Code
- 数据库、数据库管理系统和数据库系统的区别
- session维持登录状态的简单例子
- Android动态修改图片颜色的实现方式分析
- js转到jsp参数传递