zoukankan      html  css  js  c++  java
  • 字符串合并处理

    题目描述

    按照指定规则对输入的字符串进行处理。

    详细描述:

    将输入的两个字符串合并。

    对合并后的字符串进行排序,要求为:下标为奇数的字符和下标为偶数的字符分别从小到大排序。这里的下标意思是字符在字符串中的位置。

    对排训后的字符串进行操作,如果字符为‘0’——‘9’或者‘A’——‘F’或者‘a’——‘f’,则对他们所代表的16进制的数进行BIT倒序的操作,并转换为相应的大写字符。如字符为‘4’,为0100b,则翻转后为0010b,也就是2。转换后的字符为‘2’; 如字符为‘7’,为0111b,则翻转后为1110b,也就是e。转换后的字符为大写‘E’。

    举例:输入str1为"dec",str2为"fab",合并为“decfab”,分别对“dca”和“efb”进行排序,排序后为“abcedf”,转换后为“5D37BF”

    接口设计及说明:

    /*

    功能:字符串处理

    输入:两个字符串,需要异常处理

    输出:合并处理后的字符串,具体要求参考文档

    返回:无

    */

    void ProcessString(char* str1,char *str2,char * strOutput)

    {

    }

    输入描述:

    输入两个字符串

    输出描述:

    输出转化后的结果


    输入例子:
    dec fab
    

    输出例子:
    5D37BF

     1 // testt.cpp : 定义控制台应用程序的入口点。
     2 //
     3 
     4 #include "stdafx.h"
     5 
     6 #include<iostream>
     7 #include<cstring>
     8 
     9 using namespace std;
    10 
    11 void ProcessString(char* str1, char *str2, char * strOutput)
    12 {
    13     char *str3 = strcat(str1, str2);
    14     int len = strlen(str3);
    15     for (int j = len - 1; j >= 0; j--)
    16     {
    17         for (int i = 0; i < len; i++)
    18         {
    19             if (i + 2 < len)
    20             {
    21                 if (i % 2 == 0)
    22                 {
    23                     if (str3[i] > str3[i + 2])
    24                     {
    25                         char temp;
    26                         temp = str3[i + 2];
    27                         str3[i + 2] = str3[i];
    28                         str3[i] = temp;
    29                     }
    30 
    31                 }
    32                 else
    33                 {
    34                     if (str3[i] > str3[i + 2])
    35                     {
    36                         char temp;
    37                         temp = str3[i + 2];
    38                         str3[i + 2] = str3[i];
    39                         str3[i] = temp;
    40                     }
    41                 }
    42             }
    43 
    44         }
    45     }
    46     int i = 0;
    47     while (i < len)
    48     {
    49         if (str3[i] == '0')      str3[i] = '0';
    50         else if (str3[i] == '1') str3[i] = '8';
    51         else if (str3[i] == '2') str3[i] = '4';
    52         else if (str3[i] == '3') str3[i] = 'C';
    53         else if (str3[i] == '4') str3[i] = '2';
    54         else if (str3[i] == '5') str3[i] = 'A';
    55         else if (str3[i] == '6') str3[i] = '6';
    56         else if (str3[i] == '7') str3[i] = 'E';
    57         else if (str3[i] == '8') str3[i] = '1';
    58         else if (str3[i] == '9') str3[i] = '9';
    59         else if (str3[i] == 'a' || str3[i] == 'A') str3[i] = '5';
    60         else if (str3[i] == 'b' || str3[i] == 'B') str3[i] = 'D';
    61         else if (str3[i] == 'c' || str3[i] == 'C') str3[i] = '3';
    62         else if (str3[i] == 'd' || str3[i] == 'D') str3[i] = 'B';
    63         else if (str3[i] == 'e' || str3[i] == 'E') str3[i] = '7';
    64         else if (str3[i] == 'f' || str3[i] == 'F') str3[i] = 'F';
    65 
    66         i++;
    67     }
    68     strncpy(strOutput, str3, len);//末尾没有,需要手动加
    69     strOutput[len] = '';
    70 }
    71 
    72 int main(void)
    73 {
    74     char str1[1000], str2[1000];
    75     char strOutput[2000];
    76 
    77     while (cin >> str1 >> str2)
    78     {
    79         ProcessString(str1, str2, strOutput);
    80         cout << strOutput<<endl;
    81     }
    82     
    83 
    84     return 0;
    85 }
  • 相关阅读:
    windows 7 codepage id name 名称
    最大团
    三分的多种写法及对应的精度 三分套三分原理
    AC自动机
    c++ queue
    lca 欧拉序+rmq(st) 欧拉序+rmq(线段树) 离线dfs 倍增
    node *p,*q
    dfs序和欧拉序
    P3861 8月月赛A
    洛谷P3862 8月月赛B
  • 原文地址:https://www.cnblogs.com/hhboboy/p/5522275.html
Copyright © 2011-2022 走看看