在一行上输入一个长度
,由小写字母和数字构成的字符串
。
输出若干行,每行输出
个字符,代表按题意书写的结果。
hellonowcoder
hellonow coder000
在这个样例中,字符串长度为
,因此需要在第二行末尾补充
个
。
0
00000000
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<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;
}
}
} import java.util.*;
public class Main{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
while(input.hasNext()){
sb.append(input.nextLine());
sb.append(',');
}//store the input in a stringbuilder
String s = sb.toString();
String[] dataArr = s.split(",");
for(int i=0; i<dataArr.length; i++){
String target = dataArr[i];
int rowNum;
if(target.length()<=8) rowNum =1;
else if(target.length()>8 && target.length()%8==0) rowNum = target.length()/8;
else rowNum = target.length()/8+1;
int totalSize = rowNum*8;
char[] result = new char[totalSize];
int ptr =0;
while(ptr!=target.length()){
result[ptr] = target.charAt(ptr);
ptr++;
}
while(ptr!=totalSize) result[ptr++] = '0';
for(int j=0; j<totalSize; j++){
System.out.print(result[j]);
if((j+1)%8==0) System.out.println();
}
}
}
}