ZOJ 3542 2011大连现场赛D题(简单模拟)
Hexadecimal View
Time Limit: 2 Seconds Memory Limit: 65536 KB
Hexadecimal is very important and useful for computer programmers. You are requested to provide a hexadecimal view for given data. The hexadecimal view is made up of one or more rows. Every row except the last one represents 16 characters. Each row consists of three columns separated by a space:
- addr: the 4-digit hexadecimal beginning address of this row.
- dump: the hexadecimal representation of this row, separating every two characters by a whitespace. If there are less than 16 characters in the last row, pad it with spaces.
- text: the ASCII translation of this row, with uppercase characters converted to lowercase and lowercase characters converted to uppercase.
Use lowercase for the letter digits. See sample for more details.
Input
There are multiple test cases. Each line is a test case. The line is made up of no less than 1 and no more than 4096 printable characters including spaces.
Output
For each test case, output its hexadecimal view. Do not output any extra spaces after the last character of text.
Sample Input
Hex Dump
#include <cstdio>
printf("Hello, World!\n");
main = do getLine >>= print . sum . map read . words
Sample Output
0000: 4865 7820 4475 6d70 hEX dUMP
0000: 2369 6e63 6c75 6465 203c 6373 7464 696f #INCLUDE <CSTDIO
0010: 3e >
0000: 7072 696e 7466 2822 4865 6c6c 6f2c 2057 PRINTF("hELLO, w
0010: 6f72 6c64 215c 6e22 293b ORLD!\N");
0000: 6d61 696e 203d 2064 6f20 6765 744c 696e MAIN = DO GETlIN
0010: 6520 3e3e 3d20 7072 696e 7420 2e20 7375 E >>= PRINT . SU
0020: 6d20 2e20 6d61 7020 7265 6164 202e 2077 M . MAP READ . W
0030: 6f72 6473 ORDS
题目大意:
这个题目在看了A题觉得太复杂了,就开始看这个了。感觉应该是个比较简单的模拟,但是题目挂在HDU上面有问题。
0000: 4865 7820 4475 6d70 hEX dUMP
0000: 2369 6e63 6c75 6465 203c 6373 7464 696f #INCLUDE <CSTDIO
0010: 3e >
0000: 7072 696e 7466 2822 4865 6c6c 6f2c 2057 PRINTF("hELLO, w
0010: 6f72 6c64 215c 6e22 293b ORLD!\N");
0000: 6d61 696e 203d 2064 6f20 6765 744c 696e MAIN = DO GETlIN
0010: 6520 3e3e 3d20 7072 696e 7420 2e20 7375 E >>= PRINT . SU
0020: 6d20 2e20 6d61 7020 7265 6164 202e 2077 M . MAP READ . W
0030: 6f72 6473 ORDS
这是比赛时候的输出,当时看左简括号表示有点不解,其他的都想地差不多了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define INF 0x3f3f3f3f
#define maxn 105
using namespace std;
char a[5000]; //原串
char b[5]; //最前面的地址
int len,t1;
char tex[20]; //最后面的大小写转换
char dum[3]; //中间的字母转换成16进制的 void addr(int x) //最前面的地址
{
int i,p;
p=0;
int t[5];
memset(t,0,sizeof(t));
while(x)
{
t[p++]=x%16;
x/=16;
}
for(i=0;i<=2;i++)
{
if(t[2-i]<10)
b[i]=t[2-i]+'0';
else
b[i]=t[2-i]-10+'a';
}
/*for(i=2;i>=0;i--)
cout<<t[i]<<" ";
cout<<endl;*/
} void dump(char x) //中间的字母转换成16进制的
{
int i,p;
p=0;
int t[5];
memset(t,0,sizeof(t));
int l=int(x);
while(l)
{
t[p++]=l%16;
l/=16;
}
for(i=0;i<=1;i++)
{
if(t[1-i]<10)
dum[i]=t[1-i]+'0';
else
dum[i]=t[1-i]-10+'a';
}
} void text(char x) //最后面的大小写转换
{
/*if(x=='<') //坑
{
tex[t1++]='&';
tex[t1++]='l';
tex[t1++]='t';
tex[t1++]=';';
}
else*/
if(x>='a'&&x<='z')
{
tex[t1++]=x-32;
}
else if(x>='A'&&x<='Z')
tex[t1++]=x+32;
else
tex[t1++]=x;
} int main()
{
int i,pp,j;
while(gets(a))
{
len=strlen(a);
pp=len/16;
b[3]='0',b[4]='\0'; //地址最后一位无效直接为0
for(i=0;i<pp;i++)
{
addr(i);
cout<<b<<": "; //最前面的地址
t1=0;
for(j=i*16;j<i*16+16;j++)
{
dump(a[j]);
text(a[j]);
cout<<dum[0]<<dum[1];
if(j&1) cout<<" "; //每两位一个空格
}
tex[t1]='\0';
cout<<tex<<endl; //大小写转换
} t1=0;
if(len>pp*16) //开始这个地方写的>=,感谢吉吉debug
{
addr(i);
cout<<b<<": ";
for(j=i*16;j<len;j++)
{
dump(a[j]);
text(a[j]);
cout<<dum[0]<<dum[1];
if(j&1) cout<<" ";
}
tex[t1]='\0';
for(j=len;j<i*16+16;j++)
{
cout<<" "; //补空格
if(j&1) cout<<" ";
}
cout<<tex<<endl;
}
} /*int len=4096;
addr(len);
cout<<b<<endl;*/
return 0;
} //30ms 192KB
ZOJ 3542 2011大连现场赛D题(简单模拟)的更多相关文章
- HDU 5120 A Curious Matt(2014北京赛区现场赛A题 简单模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5112 解题报告:扫一遍 #include<cstdio> #include<cstr ...
- zoj 3820(2014牡丹江现场赛B题)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5374 思路:题目的意思是求树上的两点,使得树上其余的点到其中一个点的 ...
- zoj 3827(2014牡丹江现场赛 I题 )
套公式 Sample Input 33 bit25 25 50 //百分数7 nat1 2 4 8 16 32 3710 dit10 10 10 10 10 10 10 10 10 10Sample ...
- zoj 3819(2014牡丹江现场赛 A题 )
题意:给出A班和B班的学生成绩,如果bob(A班的)在B班的话,两个班级的平均分都会涨.求bob成绩可能的最大,最小值. A班成绩平均值(不含BOB)>A班成绩平均值(含BOB) &&a ...
- HDU 4119Isabella's Message2011成都现场赛I题(字符串模拟)
Isabella's Message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 2013杭州现场赛B题-Rabbit Kingdom
杭州现场赛的题.BFS+DFS #include <iostream> #include<cstdio> #include<cstring> #define inf ...
- Gym101981D - 2018ACM-ICPC南京现场赛D题 Country Meow
2018ACM-ICPC南京现场赛D题-Country Meow Problem D. Country Meow Input file: standard input Output file: sta ...
- HDU 4800/zoj 3735 Josephina and RPG 2013 长沙现场赛J题
第一年参加现场赛,比赛的时候就A了这一道,基本全场都A的签到题竟然A不出来,结果题目重现的时候1A,好受打击 ORZ..... 题目链接:http://acm.hdu.edu.cn/showprobl ...
- HDU 4816 Bathysphere (2013长春现场赛D题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 2013长春区域赛的D题. 很简单的几何题,就是给了一条折线. 然后一个矩形窗去截取一部分,求最 ...
随机推荐
- Ibatis2.3.4的一个bug
java.lang.ClassCastException: com.chat.upgrade.domain.ClientFile cannot be cast to java.lang.String ...
- loadrunner参数化总结
Select next row:Sequential,Rondom,Unique Update value on:Each iteration,Each occurrence,Once 下面分别对这两 ...
- java class生成jar包(转)
进入dos操作符窗口cd进入要打成jar包的class文件所有文件夹目录jar cvf [生成jar的名称.jar] [列出class文件] //若有多个,以空隔隔开 如:一.操作零散的单个或几个cl ...
- 图示CCScrollView的相关概念
(转载请注明原文地址:http://blog.csdn.net/while0/article/details/11527899) 见下图: 1)设置ScrollView的视口大小的函数是:setVie ...
- 推荐五个最好的MySQL GUI工具
推荐五个最好的MySQL GUI工具 在本文中,我们会介绍一些最常用的MySQL GUI工具并附上下载链接.希望大家能更好的运用这些工具. AD:网+线下沙龙 | 移动APP模式创新:给你一个做APP ...
- javascript实现快速排
其基本思路应该是排成两部分单独记录,确定枢轴,实施枢轴到左侧值我们都小于枢轴值.枢轴向右大于枢轴值.这样子不断递归下去 function quicksort(arr,low,high){ var pi ...
- TCP协议中的计时器
说明: 本文仅供学习交流.转载请标明出处,欢迎转载! 本文是下面文献相关内容的总结 [1] <TCP/IP具体解释 卷1:协议> [2] <TCP/IP协议族 第4版> [3 ...
- c语言,gdb
Get gdb call stack http://blog.csdn.net/zoufeiyy/article/details/1490241 Debugging with GDB - Examin ...
- Qt 多线程 详细函数说明及其事例
转:http://www.cnblogs.com/hicjiajia/archive/2011/02/03/1948955.html Qt线程类 Qt 包含下面一些线程相关的类:QThread 提供了 ...
- 测试 __try, __finally, __except(被__finally捕获的异常, 还会被上一级的__except捕获。反之不行)
C语言标准是没有 try-catch语法 的, M$家自己提供了一组. /// @file ClassroomExamples.c /// @brief 验证C语言的非标准try, catch #in ...