javanetbeans's blog

By javanetbeans, 13 years ago, In English

  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.io.PrintWriter;
  5. import java.math.*;
  6. import java.util.*;
  7. import java.io.*;

  8. public class C implements Runnable
  9. {
  10.     private void solve() throws IOException
  11.     {
  12.         String str = reader.readLine();
  13.         boolean male = false;
  14.         boolean female = false;
  15.         String[] ans = str.split(" ");
  16.         if(ans[0].endsWith("lios") || ans[0].endsWith("etr"))
  17.         {
  18.             male = true;
  19.         }
  20.         if(ans[0].endsWith("liala") || ans[0].endsWith("etra"))
  21.         {
  22.             female = true;
  23.         }
  24.         if((male == false && female == false) || (male && female))
  25.         {
  26.             System.out.println("NO");
  27.             return;
  28.         }
  29.        
  30.         if(ans.length == 1)
  31.         {
  32.             System.out.println("YES");
  33.             return;
  34.         }
  35.        
  36.         boolean adjective = false;
  37.         boolean noun = false;
  38.         boolean verbs = false;
  39.         int cnt = 0;
  40.         if(male == true)
  41.         {
  42.             for(int i = 0; i < ans.length; i++)
  43.             {
  44.                 if(ans[i].endsWith("lios") && noun == false)
  45.                 {
  46.                     adjective = true;
  47.                 }
  48.                 else if(ans[i].endsWith("etr") && cnt == 0)
  49.                 {
  50.                     noun = true;
  51.                     cnt++;
  52.                 }
  53.                 else if(ans[i].endsWith("initis") && noun && cnt == 1)
  54.                 {
  55.                     verbs = true;
  56.                 }
  57.                 else
  58.                 {
  59.                     System.out.println("NO");
  60.                     return;
  61.                 }
  62.             }
  63.             if(cnt == 1)
  64.                 System.out.println("YES");
  65.             else
  66.                 System.out.println("NO");
  67.         }
  68.         else if(female == true)
  69.         {
  70.             for(int i = 0; i < ans.length; i++)
  71.             {
  72.                 if(ans[i].endsWith("liala") && noun == false)
  73.                 {
  74.                     adjective = true;
  75.                 }
  76.                 else if(ans[i].endsWith("etra") && cnt == 0)
  77.                 {
  78.                     noun = true;
  79.                     cnt++;
  80.                 }
  81.                 else if(ans[i].endsWith("inites") && noun && cnt == 1)
  82.                 {
  83.                     verbs = true;
  84.                 }
  85.                 else
  86.                 {
  87.                     System.out.println("NO");
  88.                     return;
  89.                 }
  90.             }
  91.             if(cnt == 1)
  92.                 System.out.println("YES");
  93.             else
  94.                 System.out.println("NO");
  95.         }
  96.     }
  97.    
  98.     public static void main(String[] args)
  99.     {
  100.         new C().run();
  101.     }

  102.     BufferedReader reader;
  103.     StringTokenizer tokenizer;
  104.     PrintWriter writer;

  105.     public void run()
  106.     {
  107.         try
  108.         {
  109.             reader = new BufferedReader(new InputStreamReader(System.in));
  110.             tokenizer = null;
  111.             writer = new PrintWriter(System.out);
  112.             solve();
  113.             reader.close();
  114.             writer.close();
  115.         }
  116.         catch (Exception e)
  117.         {
  118.             e.printStackTrace();
  119.             System.exit(1);
  120.         }
  121.     }

  122.     int nextInt() throws IOException
  123.     {
  124.         return Integer.parseInt(nextToken());
  125.     }

  126.     long nextLong() throws IOException
  127.     {
  128.         return Long.parseLong(nextToken());
  129.     }

  130.     double nextDouble() throws IOException
  131.     {
  132.         return Double.parseDouble(nextToken());
  133.     }

  134.     String nextToken() throws IOException
  135.     {
  136.         while (tokenizer == null || !tokenizer.hasMoreTokens())
  137.         {
  138.             tokenizer = new StringTokenizer(reader.readLine());
  139.         }
  140.         return tokenizer.nextToken();
  141.     }
  142. }
  • Vote: I like it
  • 0
  • Vote: I do not like it

13 years ago, # |
  Vote: I like it 0 Vote: I do not like it
Submit it and look at results of the test?
  • 13 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    I did it. It's giving wrong answer in Test case 67. Can u help me which case I am missing?
    • 13 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it
      I failed on test 67, beacause I wasn't paying attention to the case "YES" of only one word. Then I checked that case and I failed on a testcase around 200: I checked my code for bugs, I corrected and it worked. So I suppose it is for the "only one word" case. But that's weird cause it seems you check that case
  • 13 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    this good practise)
13 years ago, # |
  Vote: I like it 0 Vote: I do not like it
why don't you use test case 67 and print out results to see what's wrong? btw, there is another nice solution to this problem using regex. :)