Hang Electric Acm--java version __java

Source: Internet
Author: User

Record the part of the answer to the ACM, pure handwriting, if there is similar, you copy me. O (∩_∩) o 1001

Problem description

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

Problem description

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

Problem description

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

Problem description

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 (); }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.