在一行上输入一个长度
,由小写字母和数字构成的字符串
。
输出若干行,每行输出
个字符,代表按题意书写的结果。
hellonowcoder
hellonow coder000
在这个样例中,字符串长度为
,因此需要在第二行末尾补充
个
。
0
00000000
#include <iostream>
#include <string>
using namespace std;
int main(){
string str;
while(cin>>str){
while(str.length()){
if(str.length()<8){
//补0输出
while(str.length()<8){
str +='0';
}
cout<<str<<endl;
str="";
}else{
//截断输出
cout<< str.substr(0,8)<<endl;
str = str.substr(8);
}
}
}
return 0;
}
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String s = new String(sc.nextLine());
if(s.length()%8 !=0 )
s = s + "00000000";
while(s.length()>=8){
System.out.println(s.substring(0, 8));
s = s.substring(8);
}
}
}
}
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
result := make([]string, 0)
for scanner.Scan() {
input := scanner.Text()
input += "0000000"
for len(input) >= 8 {
result = append(result, input[0:8])
input = input[8:]
}
}
for _, item := range result {
fmt.Println(item)
}
}
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String str = new String(sc.nextLine());
if (str.length() % 8 != 0) {
str = str + "00000000";
}
while (str.length() >= 8) {
System.out.println(str.substring(0, 8));
str = str.substring(8);
}
}
}
} #include<stdio.h>
#include<string.h>
int main(void)
{
char data[101];//定义字符数组
while(gets(data))//获取字符串
{
int m=strlen(data);//计算字符串的长度
int count=0;
for(int i=0;i<m;i++)
{
printf("%c",data[i]);//输出字符串中的每一个字符
count++; //用于控制换行符个数
if(count%8==0)
{
printf("\n");
}
}
int n=m/8,k=m-n*8,l=8-k;//计算所需要的字符零的个数
while(l--&&m%8!=0) //要保证原本字符串的长度不是八的倍数
{
printf("0");
}
printf("\n");
}
return 0;
} #include<iostream>
#include<string>
using namespace std;
int main(){
string s;
while(cin>>s){
int i;
for(i=0;i<s.length();i++){ // 正常输出字符串,每8个打印一次换行
cout<<s[i];
if(i%8==7 &&i!=0) //I处
cout<<endl;
}
bool need=false; // 注意需要特别处理,当I处恰好末尾结束(输出一次换行)时,需要让II处不再换行
while(i%8 !=0){ // 最后处理一下不足8个时,补充‘0’的个数
need = true;
cout<<'0';
i++;
}
if(i%8!=0 || need) cout<<endl; // II处
}
} #include <iostream>
#include <string>
using namespace std;
int main(){
string str;
while(getline(cin, str)) {
int len = str.size();
//cout << str;
int index = 0; // 用指针搜索
while (index < len) {
char res;
for (int j = 0; j < 8; j++) {
if (index < len) {
res = str[index++];
} else {
res = '0'; // 添0
}
cout << res;
}
cout << endl;
}
}
return 0;
} #方法一:先划分再补齐0
def apd_0(s):#补0
a = list(s)
for i in range(8-len(s)):
a.append('0')
res= ''
for item in a:
res+=item
return res
def func():
string = input()
n = len(string)
if n < 8:
res1 = apd_0(string)
print(res1)
else:
lst = []
for i in range(0,n,8):
lst.append(string[i:i+8])
res2 = apd_0(lst[-1])#结果列表最后一个字符串不满8位
lst[-1]=res2
for item in lst:
print(item)
if __name__ == '__main__':
while True:
try:
func()
except:
break #方法二:先补齐0再划分 def func(): s = input() if len(s)%8 != 0: for i in range(8-len(s)%8): s += '0' for i in range(0,len(s),8): print(s[i:i+8]) if __name__ == '__main__': while True: try: func() except: break
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str;
while( cin>>str){
if(str.length() == 0)cout<<str<<endl;//空字符
while(str.length() %8 != 0)
{
str.push_back('0');//添0
}
for(int i=0;i<str.length();i++){//隔8个输出
if(i%8==0) cout<<str.substr(i,8)<<endl;
}
}
}