- 珠心算测验
- 2016-03-30 09:28:32 @
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int num = 0;
int a[];
a = new int[101];
num = s.nextInt();
int CNT = 0;
for (int i = 0; i < num; i++) {
a[i] = s.nextInt();
}
for (int i = 0; i < num; i++) {
for (int j = 0; j < num ; j++) {
for (int k = 0; k < num && k != j; k++) {
if (a[i] == a[j] + a[k]) {
CNT++;
}
}
}
}
System.out.println(CNT);
}
}
6 条评论
-
fan672867217 LV 6 @ 2018-03-16 20:27:20
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
Scanner scan1=new Scanner(System.in);
String str=scan1.nextLine();
String s=" ";
String[] ss=str.split(s);
int[] arr=new int[n];
for(int i=0;i<n;i++)
{
int j=Integer.valueOf(ss[i]);
arr[i]=j;
}
int num=0;
for(int a=0;a<n;a++)
{
a:for(int b=0;b<n;b++)
{
if(b==a) continue;
for(int c=0;c<n;c++)
{
if(c==a || c==b) continue;
if(arr[b]+arr[c]==arr[a])
{
num++;
break a;
}
}
}
}System.out.println(num);
}
} -
2016-07-22 16:07:30@
记录信息 评测状态 Accepted 题目 P1911 珠心算测验 递交时间 2016-07-22 16:06:08 代码语言 Java 评测机 ShadowShore 消耗时间 1184 ms 消耗内存 43024 KiB 评测时间 2016-07-22 16:06:10 评测结果 编译成功 测试数据 #0: Accepted, time = 140 ms, mem = 43020 KiB, score = 10 测试数据 #1: Accepted, time = 109 ms, mem = 43024 KiB, score = 10 测试数据 #2: Accepted, time = 109 ms, mem = 43016 KiB, score = 10 测试数据 #3: Accepted, time = 109 ms, mem = 43012 KiB, score = 10 测试数据 #4: Accepted, time = 140 ms, mem = 43012 KiB, score = 10 测试数据 #5: Accepted, time = 109 ms, mem = 43020 KiB, score = 10 测试数据 #6: Accepted, time = 109 ms, mem = 43016 KiB, score = 10 测试数据 #7: Accepted, time = 109 ms, mem = 43020 KiB, score = 10 测试数据 #8: Accepted, time = 125 ms, mem = 43012 KiB, score = 10 测试数据 #9: Accepted, time = 125 ms, mem = 43016 KiB, score = 10 Accepted, time = 1184 ms, mem = 43024 KiB, score = 100 代码 import java.util.Scanner; class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int num = 0; int a[]; int y[]; y = new int[101]; a = new int[101]; num = s.nextInt(); int CNT = 0; for (int i = 0; i < num; i++) { a[i] = s.nextInt(); } for (int i = 0; i < num; i++) { for (int j = 0; j < num ; j++) { for (int k = 0; k < num && k != j; k++) { if (a[i] == a[j] + a[k]) { y[i] = 1; } } } } for (int i = 0;i < num;i++) if (y[i] == 1) CNT++; System.out.println(CNT); } }
-
2016-04-29 19:28:20@
恭喜自言自语
-
2016-03-30 09:43:29@
好吧我傻了只有下标没有排除两数相同的情况
-
2016-03-30 09:37:44@
···
import java.util.Scanner;class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int num = 0;
int a[];
a = new int[101];
num = s.nextInt();
int CNT = 0;
for (int i = 0; i < num; i++) {
a[i] = s.nextInt();
}
for (int i = 0; i < num; i++) {
for (int j = 0 ; j < num ; j++) {
for (int k = 0; k < num && k != j; k++) {
if (a[i] == a[j] + a[k]) {
CNT++;
System.out.println(a[i]+"="+a[j]+"+"+a[k]);
}}
}
}
System.out.println(CNT);
}
}
··· -
2016-03-30 09:37:13@
附上测试版。。
import java.util.Scanner;class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int num = 0;
int a[];
a = new int[101];
num = s.nextInt();
int CNT = 0;
for (int i = 0; i < num; i++) {
a[i] = s.nextInt();
}
for (int i = 0; i < num; i++) {
for (int j = 0 ; j < num ; j++) {
for (int k = 0; k < num && k != j; k++) {
if (a[i] == a[j] + a[k]) {
CNT++;
System.out.println(a[i]+"="+a[j]+"+"+a[k]);
}}
}
}
System.out.println(CNT);
}
}
- 1
信息
- ID
- 1911
- 难度
- 6
- 分类
- (无)
- 标签
- 递交数
- 17109
- 已通过
- 4523
- 通过率
- 26%
- 被复制
- 28
- 上传者