import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); String str=sc.next(); int all=str.length()-1; String[] arr=str.split("O")[0].split(""); int count=0; for(String s:arr){ if(s.equals("A")) count++; } if(count*2>all) System.out.print("A"); else if(count*2==all) System.out.print("E"); else System.out.print("B"); } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String str = scanner.next(); int countA = 0; int countB = 0; for(int i = 0; i < str.length();i++){ char c = str.charAt(i); if(c == 'A'){ countA++; } if(c == 'B'){ countB++; } } if(countA > countB){ System.out.println("A"); }else if(countA < countB){ System.out.println("B"); }else if(countA == countB){ System.out.println("E"); } } }
import java.util.HashMap; import java.util.Map; import java.util.Scanner; /** * @Title: 竞选社长 * @Remark: 假设你们社团要竞选社长,有两名候选人分别是A和B,社团每名同学必须并且只能投一票,最终得票多的人为社长. * 输入描述: * 一行,字符序列,包含A或B,输入以字符0结束。 * 输出描述: * 一行,一个字符,A或B或E,输出A表示A得票数多,输出B表示B得票数多,输出E表示二人得票数相等。 * @Author: ijunfu * @Version: 1.0.0 * @Date: 2022-03-19 */ public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); Map<Character, Integer> map = new HashMap<>(); map.put('A', 0); map.put('B', 0); char[] data = in.nextLine().toCharArray(); for(int i=0, len=data.length; i<len; i++) { char ele = data[i]; if(!map.containsKey(ele)) break; Integer count = map.get(ele); map.put(ele, ++count); } Integer a = map.get('A'); Integer b = map.get('B'); if(a > b) { System.out.println("A"); } else if(a == b) { System.out.println("E"); } else { System.out.println("B"); } in.close(); } }
import java.util.*; public class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String str = scanner.nextLine(); int count = 0; int calculation = 0; for (char ch : str.toCharArray()){ if (ch == 'A'){ count++; }if (ch == 'B'){ calculation++; } } if (count > calculation){ System.out.println("A"); }else if (count == calculation){ System.out.println("E"); }else { System.out.println("B"); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { String vote; Scanner sc1 = new Scanner(System.in); vote = sc1.nextLine(); char[] get_=vote.toCharArray(); int a=0,b=0; for(int i=0;i<get_.length-1;i++){ if(get_[i]=='A'){ a++; } else { b++; } } if(a>b){ System.out.println('A'); } else if(b>a) { System.out.println('B'); } else { System.out.println('E'); } } }
//直接将输入拆分成单个的字符串,再统计 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String[] votes = in.nextLine().split(""); int A = 0; int B = 0; for (String i : votes) { if (i.equals("A")) { A++; } else if (i.equals("B")) { B++; } } if (A > B) { System.out.println("A"); } else if (A < B) { System.out.println("B"); } else if (A == B) { System.out.println("E"); } } }
import java.util.*; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); String s = in.nextLine(); int countA = 0; int countB = 0; for(int i=0;i<s.length()-1;i++){ if(s.substring(i,i+1).equals("A")){ countA++; } else{ countB++; } } if(countA>countB){ System.out.println("A"); } else if(countA<countB){ System.out.println("B"); } else{ System.out.println("E"); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.nextLine(); String [] B = str.split("A"); String [] A = str.split("B"); String str1 = ""; String str2 = ""; for(String s : A ) { str1 = str1+s; } for(String s : B ) { str2 = str2+s; } Integer countA = str1.length(); Integer countB = str2.length(); if(countA>countB){ System.out.println("A"); } else if(countA<countB){ System.out.println("B"); } else { System.out.println("E"); } } }好像是这样吧
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner =new Scanner(System.in); int sum = 0; int countA = 0; int countB = 0; String vote = scanner.nextLine(); while (vote.length()!=sum){ switch (vote.charAt(sum)){ case 'A': countA+=1; break; case 'B': countB+=1; break; case '0': break; } sum+=1; } if(countA==countB){ System.out.println("E"); }else{ System.out.println(countA>countB?"A":"B"); } } }
import java.io.*; public class Main{ public static void main(String[] args) throws IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String str = bf.readLine(); int Bnum = str.replace("A","").length(); int Anum = str.replace("B","").length(); if(Anum>Bnum){ System.out.println("A"); }else if(Anum<Bnum){ System.out.println("B"); }else{ System.out.println("E"); } } }
import java.util.*; public class Main { public static void main(String [] args) { Scanner sc=new Scanner(System.in); int aCount=0; int bCount=0; while(sc.hasNext()) { String str=sc.next(); for(int i=0;i<str.length()-1;i++) { char s=str.charAt(i); String ss=""+s;//转成字符串类型 if(ss.equals("A")) { aCount++; } else { bCount++; } } if(aCount>bCount) { System.out.println("A"); } else if(aCount<bCount) { System.out.println("B"); } else { System.out.println("E"); } } } }