Huawei trial-string replacement (aa-bc), Huawei aa-bc

Source: Internet
Author: User

Huawei trial-string replacement (aa-bc), Huawei aa-bc

The input string (the string only contains lowercase letters 'A' to 'Z') is output after cyclic conversion according to the following rules: a-> B, B-> c ,..., Y-> z, z-> a; if the input string contains two letters in a row, the last letter must be converted twice in a row. For example, if aa is converted to bc, zz is converted to AB. If there are more than two consecutive identical letters, the third letter is counted as the first one.


Required implementation functions:

Void convert (char * input, char * output)


[Input] char * input, the input string

[Output] char * output, the output string


# Include <iostream> # include <string> using namespace std; void convert (char * input, char * output) {char * p = output; int len = strlen (input ); int I = 0; for (int j = I + 1; j <= len;) {if (input [I] = input [j]) {if (input [I] = 'y') {* p ++ = input [I] + 1; * p ++ = input [I]-24 ;} else if (input [I] = 'Z') {* p ++ = input [I]-25; * p ++ = input [I]-24 ;} else {* p ++ = input [I] + 1; * p ++ = input [I] + 2;} I = j + 1; j = I + 1 ;} else {* p ++ = input [I] + 1; I = j; j = I + 1 ;}} * p = '\ 0';} void main () {char a [1024]; char result [1024] = {'\ 0'}; while (cin> a) {convert (a, result ); cout <result <endl ;}}

Test results may be incomplete. Check for missing information:


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.