HDU-5198-Strange Class(Java+注意细节!)

78 篇文章 0 订阅
14 篇文章 0 订阅

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
 

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值