牛客中华为测试题目中的:按字节截取字符串。
import java.util.Scanner;
public class NC_045_按字节截取字符串 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String string = sc.next();
int n = sc.nextInt();
//System.out.println(string + "," + n);
StringBuffer sb= new StringBuffer();
for(int i = 0 , count = 0; i<string.length() && count<n;i++){
if(string.charAt(i)>=0 && string.charAt(i)<=255){
sb.append(string.charAt(i));
count++;
}else if(string.charAt(i) > 255){
if((count+2)>n)//如果加上汉字,字符超过要截取的字符个数,则break
break;
sb.append(string.charAt(i));
count = count + 2;
}
}
System.out.println(sb.toString());
}
}
}
牛客中华为题目中的多线程题目:循环打印“ABCD”
牛客中华为测试题目中的:按字节截取字符串。
import java.util.Scanner;
public class NC_045_按字节截取字符串 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String string = sc.next();
int n = sc.nextInt();
//System.out.println(string + "," + n);
StringBuffer sb= new StringBuffer();
for(int i = 0 , count = 0; i<string.length() && count<n;i++){
if(string.charAt(i)>=0 && string.charAt(i)<=255){
sb.append(string.charAt(i));
count++;
}else if(string.charAt(i) > 255){
if((count+2)>n)//如果加上汉字,字符超过要截取的字符个数,则break
break;
sb.append(string.charAt(i));
count = count + 2;
}
}
System.out.println(sb.toString());
}
}
}
import java.util.Scanner;
public class NC_046_多线程 {
public static void main(String[] args) {
Scanner sa = new Scanner(System.in);
while(sa.hasNext()){
StringBuffer sb = new StringBuffer();
int n = sa.nextInt();
for(int i = 0 ; i < n ; i ++){
sb.append("ABCD");
}
System.out.println(sb.toString());
}
}
}
import java.util.Scanner;
public class NC_046_多线程 {
public static void main(String[] args) {
Scanner sa = new Scanner(System.in);
while(sa.hasNext()){
StringBuffer sb = new StringBuffer();
int n = sa.nextInt();
for(int i = 0 ; i < n ; i ++){
sb.append("ABCD");
}
System.out.println(sb.toString());
}
}
}