HJ4 字符串分隔

73 阅读1分钟

描述

•输入一个字符串,请按长度为8拆分每个输入字符串并进行输出;

•长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。

输入描述:

连续输入字符串(每个字符串长度小于等于100)

输出描述:

依次输出所有分割后的长度为8的新字符串

示例1

输入:abc
输出:abc00000

具体实现

# include <stdio.h>
# include <string.h>

int main(){
	char s[100];
	while(scanf("%s",s)!=EOF){
		int n=strlen(s);
		//printf("%d\n",n);
		int i,t=0;
		int cnt=0;
		if(n%8!=0) {
			t=8-n%8;
			//printf("%d\n",t);
			for(i=n;i<n+t;i++){
				s[i]='0';
			}
		}
		for(i=0;i<n+t;i++){
			cnt++;
			printf("%c",s[i]);
			if(cnt==8) {
				printf("\n");
				cnt=0;
			}
		}
	}
}