My Calendar

2014年3月4日 星期二

UVa Problem 621 - Secret Research

UVa Problem 621 - Secret Research

Time limit: 3.000 seconds


At a certain laboratory results of secret research are thoroughly encrypted. A result of a single experiment is stored as an information of its completion: ‘positive result’, ‘negative result’, ‘experiment failed’ or ‘experiment not completed’ The encrypted result constitutes a string of digits S, which may take one of the following forms: 
  •  positive result S = 1 or S = 4 or S = 78 
  •  negative result S = S35 
  •  experiment failed S = 9S4 
  •  experiment not completed S = 190S 
(A sample result S35 means that if we add digits 35 from the right hand side to a digit sequence then we shall get the digit sequence corresponding to a failed experiment) You are to write a program which decrypts given sequences of digits.

Input 
A integer n stating the number of encrypted results and then consecutive n lines, each containing a sequence of digits given as ASCII strings. 

Output 
For each analysed sequence of digits the following lines should be sent to output (in separate lines): + for a positive result - for a negative result * for a failed experiment ? for a not completed experiment


Sample Input 
78 
7835 
19078 
944 

Sample Output 
+
 - 
*

解題方法 : 這題也是非常簡單,只需要根據題目所給的條件實作即可

import java.util.Scanner;
class UvA621 {

 public static void main(String[] args) {
  
  Scanner scan = new Scanner(System.in);

  int n = scan.nextInt();
  
  for(int i = 0 ; i < n ; i++ )
  {
   String encryptedMessage = scan.next();
   if(encryptedMessage.equals("1") || encryptedMessage.equals("4") || encryptedMessage.equals("78"))
    System.out.println("+");
   else
   {
    if (encryptedMessage.endsWith("35"))
     System.out.println("-");
    else if (encryptedMessage.startsWith("9") && encryptedMessage.endsWith("4"))
     System.out.println("*");
    else if (encryptedMessage.startsWith("190") )
     System.out.println("?");
   }
   
   
  }
 
 }

}

沒有留言:

張貼留言