HDU-5198-Strang Class(Java+詳細に注意!)


Strange Class
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 634    Accepted Submission(s): 343
Problem Description
In Vivid’s school, there is a strange class(SC). In SC, the students’ names are very strange. They are in the same format: 
anbncn (a,b,c must not be the same with each other). For example studens whose names are“abc”,”ddppqq” are in SC, however studens whose names are “aaa”,“ab”,”ddppqqq” are not in SC.
Vivid makes friends with so many students, he wants to know who are in SC.
 
Input
There are multiple test cases (about 10), each case will give a string S which is the name of Vivid’s friend in a single line.
Please process to the end of file.
[Technical Specification]
1≤|S|≤10 .
|S| indicates the length of S.
S only contains lowercase letter.
 
Output
For each case, output YES if Vivid’s friend is the student of SC, otherwise output NO.
 
Sample Input

   
   
   
   
abc bc

 
Sample Output

   
   
   
   
YES NO

 
Source
BestCoder Round #36 ($)
 
Recommend
hujie   |   We have carefully selected several similar problems for you:   5213  5212  5211  5209  5208 
英语の悪い子供靴、最后に见て、これはBestCoderの上の水题です.....
この問題は簡単です.でも細部に注意!
公式ヒント:(簡単明瞭!)
1001 Strange Class
       ,        3   。
                    。
                   。
import java.io.*;
import java.util.*;

public class Main
{

	public static void main(String[] args)
	{
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		while (input.hasNext())
		{
			boolean flag = true;
			String str = input.nextLine();
			char c[] = str.toCharArray();
   
			if (c.length % 3 != 0)                                      //  3     false
			{
				flag = false;
			}

			for (int i = 1; i < (c.length / 3); i++)                     // 1/3     false
			{
				if (c[i] != c[i - 1])
				{
					flag = false;
				}
			}
			for (int i = c.length / 3 + 1; i < (c.length * 2 / 3); i++)   //1/3 2/3        false
			{
				if (c[i] != c[i - 1])
				{
					flag = false;
				}
			}

			for (int i = c.length * 2 / 3 + 1; i < c.length; i++)        //2/3           false
			{
				if (c[i] != c[i - 1])
				{
					flag = false;
				}
			}

			if (!(c[0] != c[c.length / 3] && c[0] != c[c.length - 1] && c[c.length / 3] != c[c.length - 1]))
			{
				flag = false;                                       //            !
			}

			if (flag)
			{
				System.out.println("YES");
			} else
			{
				System.out.println("NO");
			}

		}
	}

}

 
中国語の解釈は以下の通りです.
Strange Class  
 Accepts: 519
 
 Submissions: 1749
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 65536/65536 K (Java/Others)
問題の説明
 Vivid    ,        (SC). SC ,           。           
     
      anbncn
     (a,b,c     。).  , ”abc”,”ddppqq”     SC  ,   ”aaa”,”ab”,”ddppqqq”       SC  。
Vivid       ,             SC  。

説明の入力

     
      10
      ),                S,  Vivid       。
        。

[    ]

     
      1|S|10.
     
|S|   S   .
S        .

出力の説明
       ,  Vivid    SC  ,    YES,    NO。

入力サンプル
abc
bc

出力サンプル
YES
NO