Algo-143_ Blue Bridge Cup _ Algorithm Training _ String transformation

Source: Internet
Author: User
Tags string format uppercase letter

The problem description believes that after this semester of programming training, we have mastered the operation of the string is quite skilled. Today, Mr. Xu wants to test everyone's mastery of string manipulation. Teacher Xu himself defined the 1,2,3,4, 5 of these 5 parameters refer to different 5 kinds of string operations, you need to according to the parameters passed, according to teacher Xu's rules, the input string format conversion. Teacher Xu specified the following actions:1convert all to uppercase output, such as ABC into ABC2convert all to lowercase output, such as ABC into ABC3indicates that the string is output in reverse order, such as ABC into CBA4represents converting uppercase letters in a string to lowercase letters, and lowercase letters into uppercase output, such as ABC to ABC 5 to convert all lowercase letters, and convert all successive substrings into their corresponding abbreviated output, such as ABCD conversion to a-D, Second,-represents at least 1 letters, and if it is AB, it does not need to be converted to an abbreviated form. Input format a total of one row, respectively, refers to the corresponding operation of the number and string, the two are separated by a space, the string is all composed of the English letter output format output according to the above rules converted the corresponding string sample input5Abcdee Example output a-the EE data size and the contract input string length are up to 200. 

AC Code:

1#include <stdio.h>2#include <string.h>3 #defineMAX 2004 5 intMainvoid)6 {7     inti;8     intN;9     Chararr[max+1];Tenscanf"%d%s",&n,&arr); One     Switch(n) A     { -         /*convert all to uppercase output*/ -          Case 1: the              for(i =0; I < strlen (arr); i + +) -             { -                 if(Arr[i] >='a'&& Arr[i] <='Z') -                 { +Arr[i]-= +; -                 } +             } Aprintf"%s", arr); at              Break; -         /*convert all to lowercase letters output*/ -          Case 2: -              for(i =0; I < strlen (arr); i + +) -             { -                 if(Arr[i] >='A'&& Arr[i] <='Z') in                 { -Arr[i] + = +; to                 } +             } -printf"%s", arr); the              Break; *         /*output the entire string in reverse order*/ $          Case 3:Panax Notoginseng              for(i = strlen (arr)-1; I >=0; I--) -             { theprintf"%c", Arr[i]); +             } A              Break; the         /*converts the corresponding uppercase letter in a string to lowercase letters, lowercase to uppercase*/ +          Case 4: -              for(i =0; I < strlen (arr); i + +) $             { $                 if(Arr[i] >='A'&& Arr[i] <='Z') -                 { -Arr[i] + = +; the                 } -                 Else if(Arr[i] >='a'&& Arr[i] <='Z')Wuyi                 { theArr[i]-= +; -                 } Wu             } -printf"%s", arr); About              Break; $         /*convert all to lowercase letters, - and converts all successive strings into the corresponding abbreviated form output.*/ -          Case 5: -              for(i =0; I < strlen (arr); i + +) A             { +                 if(Arr[i] >='A'&& Arr[i] <='Z') the                 { -Arr[i] + = +; $                 } the             } theprintf"%c", arr[0]); then =0; the              for(i =1; I < strlen (arr); i + +)  -             { in                 if(arr[i]-arr[i-1] ==1&& arr[i+1]-arr[i] = =1) the                 { then + +; About                     Continue; the                 } the                 if(n) the                 { +printf"-"); -                 } theprintf"%c", Arr[i]);Bayin =0; the             }             the              Break; -         default: -              Break; the     } the      the     return 0; the}

Algo-143_ Blue Bridge Cup _ Algorithm Training _ String transformation

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.