CCF部分真题代码(Java)
2013-12-1//出现次数最多的数
package demo;
import java.util.*;
public class Test2{
public static void main(String[] args){
new Test2().run();
}
public void run(){
System.out.println(请输入:);
@SuppressWarnings(resource)
Scanner fin = new Scanner(System.in);
int N =fin.nextInt();
int[]count = new int[10001];
for(int i=0;iN;++i){
++count[fin.nextInt()];
}
int maxCount =-1;
int result = 0;
for (int i=1;i=10000;++i){
if(count[i]maxCount){
maxCount=count[i];
result = i;
}
}
System.out.println(result);
}
}
2014-03-01//相反数
package demo;
import java.util.*;
public class Test3 {
public static void main(String[] args) {
new Test3().run();
}
public void run() {
@SuppressWarnings(resource)
// 输入一个正整数 1~500
Scanner input = new Scanner(System.in);
System.out.println(请输入一个1~500的整数:);
int N = input.nextInt();
int[] value = new int[N];
int count = 0;
System.out.println(请输入 + N + 个正整数,且每个数绝对值不超过1000,不同的数);
// 加入数组
for (int i = 0; i N; ++i) {
value[i] = input.nextInt();
}
// 双层循环查找
for (int i = 0; i N; i++) {
for (int j = i + 1; j N; j++) {
if (value[i] == (-value[j])) {
count++;
}
}
}
System.out.println(count);
}
}
201309-3//字符串匹配
package demo;
import java.util.Scanner;
public class Test4 {
public static void main(String[] args) {
@SuppressWarnings(resource)
Scanner reader = new Scanner(System.in);
String str = reader.next();
int p = reader.nextInt();
int n = reader.nextInt();
int d = 0;
String[] re = new String[n];
for (int t = 0; t n; t++) {
String s = reader.next();
if (p == 0) {
s = s.toLowerCase();
str = str.toLowerCase();
}
if (s.contains(str)) {
re[d] = s;
d = d + 1;
}
}
for (int i = 0; i d; i++)
System.out.println(re[i]);
}
}
2014-09-1 //相邻数对
package demo;
import java.util.*;
public class Test5 {
public static void main(String[] args) {
new Tes
您可能关注的文档
最近下载
- 个人简历表格填写2021简历模板.docx VIP
- 针灸推拿学习题库(附答案).docx VIP
- 毕业设计(论文)-五边形凸台零件铣削加工.doc VIP
- 2026届山东省淄博市高三上学期期末考试(摸底质量检测)历史试题(含答案).docx VIP
- 常见词组固定搭配.pdf VIP
- 2023年山东泰安中考地理试题及答案.pdf VIP
- 胎动管理专家共识最新2025.pptx
- (小学综合实践课标复习题全.doc VIP
- 0—3岁婴幼儿心理发展与教育 第四章 0-3岁婴幼儿心理发展与教育 课件PPT.pptx VIP
- 0—3岁婴幼儿心理发展与教育 第三章 0-3岁婴幼儿心理发展与教育 课件PPT.pptx VIP
原创力文档

文档评论(0)