输入数据为一行,包含9997个数字,空格隔开。
输出为一行,包含一个数字。
同题设例子输入
2
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean[] fs = new boolean[10001];
for(int i = 0; i < 9997; i++) {
fs[sc.nextInt()] = true;
}
String ans = "";
for(int i = 1; i < 10001; i++) {
if(!fs[i]) {
ans += i;
}
}
System.out.println(Long.parseLong(ans) % 7);
}
} import java.util.*;
import java.math.*;
public class Main{
public static void main(String[]args){
Scanner s= new Scanner(System.in);
int [] numarr =new int[10001];
int count=9997;
while(count-->0)
numarr[s.nextInt()]=1;
String str="";
for(int i=1;i<=10000;i++)
if(numarr[i]==0)
str+=String.valueOf(i);
System.out.println( Long.parseLong(str)%7 );
}
} import java.util.Scanner;
import java.util.Arrays;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
//创建数组空间10000,
int[] nums = new int[10000];
//新数组存丢失的三个元素
int[] lost = new int[3];
//输入数据,并排序 nums[0]=1,nums[1]=2,...nums[9999]=10000;
//输入的数据是无序的,可以利用此方法排序,空缺的元素位置为0
for(int i=0;i<9997;i++){
int n = sc.nextInt();
nums[n-1] = n;
}
int j=0;
//遍历输入的数组,如果数值的值为0,则为丢失的元素,把它并入新数组
for(int i=0;i<nums.length;i++){
if(nums[i] == 0){
lost[j]=i+1;
j++;
}
}
//数组排序
Arrays.sort(lost);
//数组作为字符串拼接
String n = lost[0]+String.valueOf(lost[1])+lost[2];
//使用Long对象存放数据,Integer可能会溢出(结果可能为12位数)
System.out.println(Long.valueOf(n) % 7);
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
boolean[] numExist = new boolean[10000];
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
numExist[sc.nextInt() - 1] = true;
}
StringBuilder newNum = new StringBuilder();
for (int i = 1; i <= 9997; i++) {
if (!numExist[i - 1])
newNum.append(i);
}
System.out.println(Long.parseLong(newNum.toString()) % 7);
}
} 使用boolean存储数字是否存在更节省空间。舒服
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int []arr = new int[10001];
for(int i = 1;i <= 9997;i ++) {
int n = scanner.nextInt();
arr[n] = 1;
}
int []a = new int[3];
int j = 0;
for (int i = 1;i <= 10000;i ++) {
if (arr[i] == 0) {
a[j ++] = i;
}
continue;
}
Arrays.sort(a);
String s = String.valueOf(a[0]) + String.valueOf(a[1]) + String.valueOf(a[2]);
long res = Long.parseLong(s);
System.out.println(res % 7);
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] strings = br.readLine().split(" ");
boolean[] tmp = new boolean[10000];
for (int i = 0; i < strings.length; i++) {
int string2int = Integer.parseInt(strings[i]);
tmp[string2int - 1] = true;
}
int index = 0;
int[] arr = new int[3];
for (int i = 0; i < 10000; i++) {
if (tmp[i] != true) {
arr[index++] = i + 1;
if (index == 3)
break;
}
}
Arrays.sort(arr);
StringBuilder sb = new StringBuilder();
sb.append(arr[0]);
sb.append(arr[1]);
sb.append(arr[2]);
long k = Long.parseLong(sb.toString());
System.out.println(k % 7);
}
}
import java.util.ArrayList;
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int[] nums=new int[10000];
ArrayList<Integer> list=new ArrayList<>();
for(int i=0;i<9997;i++){
int num=sc.nextInt();
nums[num-1]=1;
}
for(int i=0;i<10000;i++){
if(nums[i]==0){
list.add(i+1);
}
if(list.size()==3)break;
}
StringBuffer str = new StringBuffer();
for (int i = 0; i < 3; i++) {
str.append(list.get(i));
}
String numStr = str.toString();
long newNum = Long.parseLong(numStr);
System.out.println(newNum%7);
}
} import java.util.*;
import java.math.*;
public class Main{
//需要的数据空间,因为是1到10000所以需要10001个空间
static int [] numarr =new int[10001];
public static void main(String[]args){
Scanner s= new Scanner(System.in);
int t=0;
//去除3个数字后剩余数量9997
for(int i=0;i<9997;i++){
t=s.nextInt();
numarr[t]=1;
}
StringBuilder st = new StringBuilder();
//遍历一次找到数组中为0的数据的下标,就是我们要找的三个数值
for(int i=1;i<=10000;i++){
if(numarr[i]==0){
st.append(i);
}
}
BigInteger b =new BigInteger(st.toString());
System.out.println(b.mod(BigInteger.valueOf(7)));
}
} //好好读题,注意溢出问题
import java.util.*;
public class Main {
private final static int count = 9997;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] array = new int[count];
int[] loss = new int[3];
for (int i = 0; i < count; i++)
array[i] = in.nextInt();
Arrays.sort(array);
int index = 0;
for (int i = 0, j = 1; index < 3;) {
if (array[i] != j ) {
loss[index++] = j;
j++;
} else {
i++; j++;
}
}
Arrays.sort(loss);
String res = "" + loss[0] + loss[1] + loss[2];
System.out.println(Long.parseLong(res) % 7);
}
}
----------------------------------------------------------------------
//代码改进
import java.util.*;
public class Main {
private final static int count = 10000;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] array = new int[count + 1];
int[] loss = new int[3];
for (int i = 0; i < count - 3; i++)
array[in.nextInt()] = 1;
int index = 0;
for (int i = 1; i <= count; i++) {
if (array[i] == 0)
loss[index++] = i;
}
Arrays.sort(loss);
String res = "" + loss[0] + loss[1] + loss[2];
System.out.println(Long.parseLong(res) % 7);
}
}
----------------------------------------------------------------------
//再改进
import java.util.*;
public class Main {
private final static int count = 10000;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] array = new int[count + 1];
for (int i = 0; i < count - 3; i++)
array[in.nextInt()] = 1;
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= count; i++) {
if (array[i] == 0) sb.append(i);
}
System.out.println(Long.parseLong(sb.toString()) % 7);
}
}
import java.util.LinkedList; import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner scanner = new Scanner(System.in); LinkedList<Integer> n = new LinkedList<>(); StringBuffer sb = new StringBuffer(); int count = 0; long num; while (scanner.hasNext()) { for (int i = 0; i < 9997; i++) { n.add(scanner.nextInt()); } for (int i = 1; i <=10000; i++) { if (!n.contains(i)) { sb.append(i); count = count + 1; if (count == 3) { break; } } } num = Long.parseLong(sb.toString()); System.out.println(num % 7); } } }这题感觉思路理明白了就超简单,就是先把那9997个数存到一个LinkedList里面,然后用LinkedList的contain方法来判断哪些数不在,攒够三个不在的数就跳出循环就可以了
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class StringUtil {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String str[] = bf.readLine().split(" ");
String res = "";
for(int i=1; i<str.length; i++){
int p = Integer.valueOf(str[i-1]);
int n = Integer.valueOf(str[i]);
while(p+1 != n){
res += p+1;
p++;
}
}
long resi = Long.valueOf(res)%7;
System.out.println(resi);
}
}