String completion output

Source: Internet
Author: User

Question:

Enter two numbers (such as). The first one indicates the number of lines of the string to be accepted, and the second one indicates that each line string is output to different rows according to the specified number, fill in the missing ones with 0.

Input: 2, 8

ABC
Abcdefghijk

Output:

Abc00000

Abcdefgh

Ijk00000

 1 #include<stdio.h> 2 void split(char *s, int n) 3 { 4     char sub[50]; 5     int i,j; 6     for(i=0; s[i] != ‘\0‘; i++) 7             ; 8     for(j=i; j%n != 0; j++) 9         s[j] = ‘0‘;10     s[j] = ‘\0‘;11     //printf("%s\n",s);12     j = 0;13     for(i=0; s[i] != ‘\0‘; i++)14     {15         sub[j++] = s[i];16         if (j%n == 0 && i!=0){17             sub[j] = ‘\0‘;18             printf("%s\n",sub);19             j = 0;20         }21     }22 }23 24 int main()25 {26     int n,m;27     char s[50];28     scanf("%d%d",&n,&m);29     while(n--){30         scanf("%s",s);31         split(s,m);32     }33 }

 

 

String completion output

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.