C language-->> left-handed string

Source: Internet
Author: User

Problem Description:

Suppose there is a string: ABCDE

L-One character get new string Bcdea

L two characters get new string Cdeab

Code implementation:

#include <stdio.h> #include <string.h>void reverse (char *left,char *right) {while (left<right) {char tmp=  *left;  *left=*right;  *right=tmp;  left++; right--; }}void Left_move (char *str,int k,int len) {reverse (str,str+k-1); reverse (str+k,str+len-1); reverse (str,str+len-1);} int main () {char str[]= "ABCDE";/* Original string: abcde*/int k=0; int Len=strlen (str); printf ("Please input rotate several characters:"); scanf ("%d", &k);  while (K>len) {printf ("The number is too large, please re-enter:"); scanf ("%d", &k); } left_move (Str,k,len); printf ("%s\n", str); return 0;}

Results:

650) this.width=650; "title=" _}1u) 6}c19nonluz[puja{t.png "src=" http://s2.51cto.com/wyfs02/M02/76/7D/ Wkiol1zueqgagmclaaajzeaoark332.png "alt=" Wkiol1zueqgagmclaaajzeaoark332.png "/>

This article is from the "Pzd Chuan Feng" blog, please make sure to keep this source http://xujiafan.blog.51cto.com/10778767/1716553

C language-->> left-handed string

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.