• HDU 4054


    http://acm.hdu.edu.cn/showproblem.php?pid=4054

    模拟题,对一个字符串的每个字符输出16进制表示的数字,每行处理16个字符,后面再把这16个字符输出,大小写互换

    利用%x可以直接输出16进制,轻松秒掉

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <map>
    #include <algorithm>
    #include <queue>
    #include <cmath>
    #include <stack>
    #include <set>
    
    using namespace std;
    
    char str[6000];
    
    int main(){
        while(gets(str)){
            int len=strlen(str);
            for(int i=0;i<len;i+=16){
                printf("%04x:",i);
                int odd=1;
                int cnt=0;
                for(int j=i;j<len && j<i+16;j++){
                    if(odd&1){
                        odd=0;
                        printf(" %x",str[j]);
                        cnt+=3;
                    }
                    else{
                        odd=1;
                        printf("%x",str[j]);
                        cnt+=2;
                    }
                }
                for(int j=0;j<41-cnt;j++)
                    putchar(' ');
                for(int j=i;j<len && j<i+16;j++){
                    if(str[j]>='a' && str[j]<='z'){
                        printf("%c",str[j]-'a'+'A');
                    }
                    else if(str[j]>='A' && str[j]<='Z'){
                        printf("%c",str[j]-'A'+'a');
                    }
                    else{
                        printf("%c",str[j]);
                    }
                }
                putchar('
    ');
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Python3 函数return
    Python3 函数参数
    计算机组成原理基础
    解决 Python2 和 Python3 的共存问题
    管理本地用户和组
    Linux 常用命令(二)
    Linux 控制台
    Linux 常用命令(一)
    Linux中的目录功能(Red Hat 7)
    自定义属性使用
  • 原文地址:https://www.cnblogs.com/xiaohongmao/p/4133218.html
Copyright © 2020-2023  润新知