杭電ACM——Java版
阿新 • • 發佈:2019-02-02
記錄杭電ACM的部分答案,純手寫,如有雷同,算你抄我的。o(∩_∩)o
1001
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int a;
while(scan.hasNextInt()){
a=scan.nextInt();
System.out.println(sum(a));
System.out.println();
}
}
static int sum(int a){
int sum=0;
for(int i=1;i<=a;i++){
sum+=i;
}
return sum;
}
}
1002
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int a=scan.nextInt();
if(a>=1&&a<=20){
BigInteger[] a1 =new BigInteger[a+1];
BigInteger[] a2 =new BigInteger[a+1];
for(int i=1;i<=a;i++){
a1[i]=scan.nextBigInteger();
a2[i]=scan.nextBigInteger();
}
for (int i=1;i<a;i++){
System.out.println("Case"+" "+i+":\r\n"+
a1[i]+" + "+a2[i]+" = "+a1[i].add(a2[i])+"\r\n");
}
System.out.println("Case"+" "+a+":\r\n"+
a1[a]+" + "+a2[a]+" = "+a1[a].add(a2[a]));
}else{
System.out.println(0);
}
}
}
1003
import java.io.BufferedInputStream;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan=new Scanner(new BufferedInputStream(System.in));
int count=scan.nextInt();
int[] result=new int[count*3];
if(count>20&&count<1)
return ;
int n=0;
while(count-->0){
int thissum=0,maxsum=0,mstart=1,mend=1,mtemp=1;
int N=scan.nextInt();
for(int i=1;i<=N;i++){
int tmp=scan.nextInt();
thissum+=tmp;
if(thissum<0){
thissum=0;
mtemp=i+1;
}
if(thissum>maxsum){
maxsum=thissum;
mend=i;
mstart=mtemp;
}
}
result[n*3+0]=maxsum;
result[n*3+1]=mstart;
result[n*3+2]=mend;
n++;
}
for(int k=0;k<n;k++){
System.out.println("Case "+(k+1)+":");
System.out.println(result[k*3+0]+" "+result[k*3+1]+" "+result[k*3+2]);
if(k!=n-1){
System.out.println();
}
}
}
}
1004
import java.io.BufferedInputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
public class Main {
public static void main(String[] args) {
Scanner scan=new Scanner(new BufferedInputStream(System.in));
while(scan.hasNext()){
int count=scan.nextInt();
if(count==0){
break;
}
Map<String, Integer> map=new HashMap<String, Integer>();
while(count-->0){
String str=scan.next();
int tmp=0;
if(map.containsKey(str)){
tmp=map.get(str)+1;
}else{
tmp=0;
}
map.put(str, tmp);
}
String result=null;
int max=-1;
Set<String> keys=map.keySet();
for(String s:keys){
if(map.get(s)>max){
max=map.get(s);
result=s;
}
}
System.out.println(result);
}
scan.close();
}
}