HDU 4054 Hexadecimal View 模拟

戳这里:HDU 4054

//复习一下 cin.getline() 的用法

 1 #include "bits/stdc++.h"
 2 using namespace std;
 3 char str[5000];
 4
 5 char Change(char c)
 6 {
 7     if(‘A‘ <= c && c <= ‘Z‘) {
 8         return c + 32;
 9     }
10     if(‘a‘ <= c && c <= ‘z‘) {
11         return c - 32;
12     }
13     return c;
14 }
15
16 int main()
17 {
18     while(cin.getline(str, 4500)) {
19         int len = strlen(str);
20         int row;
21         for(row = 0; row < len; row += 16) {
22             printf("%04x: ", row);
23             int i;
24             for(i = row; i < row + 16; i += 2) {
25                 if(i < len)
26                     printf("%02x", str[i]);
27                 else
28                     printf("  ");    //两个空格
29                 if(i + 1 < len)
30                     printf("%02x ", str[i + 1]);    //后有一个空格
31                 else
32                     printf("   ");    //两个空格
33             }
34
35             for(i = row; i < row + 16 && i < len; ++i) {
36                 printf("%c", Change(str[i]));
37             }
38             printf("\n");
39         }
40     }
41 }
时间: 2024-10-24 08:27:06

HDU 4054 Hexadecimal View 模拟的相关文章

HDU 4054 - Hexadecimal View

先上一枚水题,模拟. /* ID:esxgx1 LANG:C++ PROG:hdu4054 */ #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int main(void) { #ifndef ONLINE_JUDGE freopen("in.txt", "r", st

hdu 1175 连连看(模拟循环队列)

连连看 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18149    Accepted Submission(s): 4741 Problem Description "连连看"相信很多人都玩过.没玩过也没关系,下面我给大家介绍一下游戏规则:在一个棋盘中,放了很多的棋子.如果某两个相同的棋子,可以通过一条线连起来(这条

HDU 4608 I-number--简单模拟

I-number Time Limit: 5000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 The I-number of x is defined to be an integer y, which satisfied the the conditions below: 1.  y>x; 2.  the sum of each digit of y(under base 10) is the multiple of 10; 3.  among all

HDU 5880 Family View (AC自动机)

Family View Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Description Steam is a digital distribution platform developed by Valve Corporation offering digital rights management (DRM), multiplayer gaming and socia

hdu 4831 Scenic Popularity(模拟)

题目链接:hdu 4831 Scenic Popularity 题目大意:略. 解题思路:对于休闲区g[i][0]和g[i][1]记录的是最近的两个景点的id(只有一个最近的话g[i][1]为0),对于景点来说,g[i][0]为-1(表示该id对应的是景点),g[i][1]为该景点的热度值.主要就是模拟,注意一些细节就可以了. #include <cstdio> #include <cstring> #include <cstdlib> #include <alg

hdu 3125 Slash(模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3125 Problem Description The American English slash (/) is a punctuation mark. In the early modern period, in the Fraktur script, which was widespread through Europe in the Middle Ages, one slash(/) repr

hdu 4858 项目管理(vector模拟)

# include <stdio.h> # include <algorithm> # include <string.h> # include <vector> # define N 100005 using namespace std; vector<int>g[N]; int node[N]; int slove(int x) { int sum=0,i; for(i=0;i<g[x].size();i++) { sum+=node[

hdu 4941 STL HASH 模拟

http://acm.hdu.edu.cn/showproblem.php?pid=4941 比赛的时候现学的map的find...以前都是用下标做的,但是map用下标查询的话,如果查询的元素不存在,会插入一个新的元素. 贴一个map查找元素找到和找不到的模板 map<pair<int,int>,int>::iterator it=poshash.find(tmppos);//pair<int,int>poshash; int pp; if(it == poshash.

HDU 4022 Bombing STL 模拟题

手动模拟.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; #define N 10100 #define inf 1000000010 map<