A;重合次数
package no13_guosai;
public class test1 {
public static void main(String[] args) {
int i=22,j=13,k=6;
int sum=0;
for ( ;;i++){
if (i==60){
i=0;
j++;
}
if (j==60){
j=0;
k++;
}
if (i==j) sum++;
if (i==20&&j==36&&k==14){
System.out.println(sum);
System.exit(0);
}
}
}
}
我的答案502,正确答案494,为什么多了8次?因为有8次是时针分针秒针都重合的,这题目也没说三个都重合也不算啊,不理解
B:数数
import java.util.Scanner;
public class test2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n,m;
int sum=0;
n=scanner.nextInt();
m=scanner.nextInt();
String[] s=new String[m];
for (int i = 0; i < m; i++) {
s[i]=((Integer)scanner.nextInt()).toString();
}
for (int i = 1; i < n; i++) {
String number=new Integer(i).toString();
for (int j = 0; j <= m; j++) {
if (j!=m&&number.contains(s[j])){
break;
}
if (j==m) {
// System.out.println(i);
// System.out.println("....");
sum++;
}
}
}
System.out.println(sum);
}
}
C:左移右移
import java.util.Scanner;
public class test3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N=scanner.nextInt();
int M=scanner.nextInt();
scanner.nextLine();
int arg[]=new int[N];
for (int i = 0; i < N; i++) {
arg[i]=i+1;
}
for (int i = 0; i < M; i++) {
String s=scanner.nextLine();
char c0=s.charAt(0);
char c2=s.charAt(2);
if (c0=='L'){
lift(arg,c2);
}
else right(arg,c2);
}
for (int i = 0; i < arg.length; i++) {
System.out.print(arg[i]+" ");
}
}
static void lift(int[] a,int x){
x-=48;
int address =0;
for (int i = 0; i <a.length ; i++) {
if (a[i]==x) address =i;
}
for (int i = address; i >0; i--) {
a[i]=a[i-1];
}
a[0]=x;
}
static void right(int[] a,int x){
x-=48;
int address =0;
for (int i = a.length-1; i >=0 ; i--) {
if (a[i]==x) address =i;
}
for (int i = address; i <a.length-1; i++) {
a[i]=a[i+1];
}
a[a.length-1]=x;
}
}