CPA招新Ⅰ (10分)
新學期開始啦,我們CPA是2019年6月成立的,創建時有20位元老。現在需要招新啦,每年新學期社團服務中心會組織百團大戰。我們CPA迎來第一次招新,我們很期待迎來新成員。 每天都有元老去招新,每招到一個萌新,招新人會在紙上寫一個大寫字母。CPA共有競賽部、宣傳部、辦公部、組織部四個部門。我們規定A代表競賽部(Competition department),B代表宣傳部(Propaganda Department)、C代表辦公部(Office)、D組織部(Organization Department)。社團招新後需要統計每一個部門有多少人?
輸入格式:
輸入一行字符串,字符串長度不大於10000。
輸出格式:
每輸出一個部門換行。
輸入樣例:
AABBCCDD
輸出樣例:
Competition department 2 people!
Propaganda Department 2 people!
Office 2 people!
Organization Department 2 people!
備註:
也許有人調皮不止ABCD四個字符,真實人數以ABCD爲準。
代碼如下:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
int a = 0;
int b = 0;
int c = 0;
int d = 0;
for (int i = 0; i < s.length(); i++) {
if(s.charAt(i) == 'A') {
a++;
}else if(s.charAt(i) == 'B') {
b++;
}else if(s.charAt(i) == 'C') {
c++;
}else if(s.charAt(i) == 'D'){
d++;
}
}
System.out.println("Competition department " + a + " people!");
System.out.println("Propaganda Department " + b + " people!");
System.out.println("Office " + c + " people!");
System.out.println("Organization Department " + d + " people!");
sc.close();
}
}