现在你在玩一款游戏,叫做节奏小师。它有三种判定
P : Perfect完美,加200分。
G : Great很棒,加100分。
M : Miss错过,不加分也不扣分,但累计三次Miss就会输掉游戏。
另外有一种奖励是连击奖励。一旦连续三个Perfect之后,后续连击的Perfect分数将变成250分,但一旦打出了Great或者Miss则连击数将重新开始计算。
你的任务是根据游戏记录计算分数。特别地,失败记为零分。
现在你在玩一款游戏,叫做节奏小师。它有三种判定
P : Perfect完美,加200分。
G : Great很棒,加100分。
M : Miss错过,不加分也不扣分,但累计三次Miss就会输掉游戏。
另外有一种奖励是连击奖励。一旦连续三个Perfect之后,后续连击的Perfect分数将变成250分,但一旦打出了Great或者Miss则连击数将重新开始计算。
你的任务是根据游戏记录计算分数。特别地,失败记为零分。
一行一个字符串,描述你的游戏记录。
对于前40%数据,保证字符串长度小于等于100
对于100%数据,保证字符串长度小于等于10000
一行一个正整数表示得分
PPPPPGPPMP
1800
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); char[] chars = br.readLine().trim().toCharArray(); int Pcnt = 0; // 连续打出Perfect的计数 int Mcnt = 0; int score = 0; for(int i = 0; i < chars.length; i++){ if(chars[i] == 'P'){ Pcnt ++; if(Pcnt > 3) score += 250; // 连续3次以上打出Perfect,每次+250 else score += 200; // 常规打出Perfect,每次+200 }else if(chars[i] == 'G'){ score += 100; Pcnt = 0; // 打出Great,Perfect就重新计数 }else{ Mcnt ++; Pcnt = 0; // 打出Miss,Perfect也重新计数 if(Mcnt == 3){ // 累积3次失败就输掉游戏 score = 0; break; } } } System.out.println(score); } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); String string=scanner.nextLine(); System.out.println(name(string)); } public static int name(String s) { int score=0; int countP=0; int countM=0; int p=200,g=100; if (s.length()==0) { return 0; } int i=0; while (i<s.length()) { while (i<s.length() && 'P'==s.charAt(i)) { countP++; if (countP>3) { score+=250; }else { score+=p; } i++; } while (i<s.length() && 'G'==s.charAt(i)) { countP=0; score+=g; i++; } while (i<s.length() && 'M'==s.charAt(i)) { countP=0; countM++; if (countM==3) { return 0; } i++; } } return score; } }
import java.util.*; public class Main{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.next(); int score = 0; int perfect = 0; int miss = 0; for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if ( ch == 'P') { miss = 0; perfect++; if (perfect <= 3) { score += 200; }else if (perfect > 3) { score += 250; } } else if (ch == 'G') { perfect = 0; miss = 0; score += 100; } else if (ch == 'M') { perfect = 0; miss++; if (miss == 3) { score = 0; break; } } } System.out.println(score); } }
public static void main(String[] args) { int pScore = 200; int gScore = 100; int sum = 0; List<String> importList = Arrays.asList("P", "P", "P", "P", "P", "G", "P", "P", "M", "P"); Map<Integer, String> map = new HashMap<>(); for (int i = 0; i < importList.size(); i++) { map.put(i,importList.get(i)); if ("M".equals(map.get(i)) && "M".equals(map.get(i - 1)) && "M".equals(map.get(i - 2))){ sum = 0; return; } if ("P".equals(importList.get(i))) { sum += pScore; if ("P".equals(map.get(i)) && "P".equals(map.get(i - 1)) && "P".equals(map.get(i - 2)) && "P".equals(map.get(i - 3))) { sum += 50; } } if ("G".equals(importList.get(i))) { sum += gScore; } } System.out.println(sum); }