zoukankan      html  css  js  c++  java
  • hdu 4054 字符串处理

    现场赛中最水的题,发现这题时比赛已经进行了半个小时,可是我打了半个小时还没有搞定,看着旁边的队伍一个个地升起气球,更加紧张,后面还有一点小问题干脆让海峰写了。今天发现杭电加了现场赛的题目,20分钟就把这题给过了。看来赛场上的心理素质还得训练,不然正式比赛的时候难以发挥出最好的水平~

    /*
    * hdu4054/win.cpp
    * Created on: 2011-10-6
    * Author : ben
    */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <iostream>
    #include <queue>
    using namespace std;
    const int MAX_LEN = 4200;
    char ori[MAX_LEN], newstr[MAX_LEN];

    void work() {
    strcpy(newstr, ori);
    int len = strlen(ori);
    for (int i = 0; i < len; i++) {
    if (newstr[i] >= 'A' && newstr[i] <= 'Z') {
    newstr[i] += 32;
    } else if (newstr[i] >= 'a' && newstr[i] <= 'z') {
    newstr[i] -= 32;
    }
    }
    int I = 0;
    while (I * 16 + 16 <= len) {
    printf("%04x: ", I * 16);
    for (int j = 0; j < 16; j += 2) {
    printf("%x%x ", ori[I * 16 + j], ori[I * 16 + j + 1]);
    }
    for (int j = 0; j < 16; j++) {
    putchar(newstr[I * 16 + j]);
    }
    putchar('\n');
    I++;
    }
    if (I * 16 < len) {
    int J = len - I * 16;
    printf("%04x: ", I * 16);
    for (int j = 0; j < J - 1; j += 2) {
    printf("%x%x ", ori[I * 16 + j], ori[I * 16 + j + 1]);
    }
    if (J % 2 == 1) {
    printf("%x ", ori[I * 16 + J - 1]);
    }
    int K = 16 - J;
    for (int j = 0; j < K - 1; j += 2) {
    printf(" ");
    }
    for (int j = 0; j < J; j++) {
    putchar(newstr[I * 16 + j]);
    }
    putchar('\n');
    }
    }

    int main() {
    #ifndef ONLINE_JUDGE
    freopen("data.in", "r", stdin);
    #endif
    while (gets(ori)) {
    work();
    }
    return 0;
    }



  • 相关阅读:
    微信小程序实现运动步数排行(可删除)
    微信小程序实现运动步数排行(可删除)
    一个文艺的在线生成漂亮的二维码工具网站
    微信小程序常见的UI框架/组件库总结
    天天快车是款精细的游戏
    MHA的几种死法-叶良辰
    编译maxscale
    mydbtest文档
    高山仰止
    docker居然需要3.10以上的内核
  • 原文地址:https://www.cnblogs.com/moonbay/p/2199952.html
Copyright © 2011-2022 走看看