TeamNames

发布于 2020-10-09  209 次阅读




TeamNames

A certain ICPC regional contest has specific requirements for the names of the competing teams. One of the reasons this is done is so spectators can determine which school each team is from. The requirements for a team name are specified on the website for the region as shown here:

• Each team name must consist of the institution name (greater than 1 character but less than or equal to 8 characters) followed by a hyphen (-) followed by a team name (greater than 0 characters but less than or equal to 24 characters). Please note that spaces are counted as characters.

• Format: INSTITUTION-TEAMNAME INSTITUTION = University name or abbreviation. 1 < length(INSTITUTION ) <= 8. TEAMNAME = Your team name. 1 <= length(TEAMNAME) <= 24.

Write a program that determines if a supplied string is a valid team name for this region.

Input
The input consists of a single line containing a string of characters at least one character long and no more than 80 characters long. The input string will not have any leading or trailing spaces. The INSTITUTION may not contain hyphens (obviously). The TEAMNAME, however, may contain hyphens.

Output
The single output line consists of the word YES if the string represents a valid team name for the region or NO if the string does not represent a valid team name for the region.

Sample Input
Stevens-1

Sample Output
YES

Sample Input 2
INSTITUTION-TEAMNAME

Sample Output 2
NO

Sample Input 3
Dragons

Sample Output 3
NO
题意:输入一串字符串,倘若该字符串中有连字符“-”,并且连字符前的名称大于一个字符但小于或等于八个字符,连字符后的名称大于0个字符但小于或等于24个字符,则输出YES,否则输出NO;
思路:水题,按题意模拟即可。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	string s;
	getline(cin,s);
	int a,b,c,n;
	a=b=c=0;
	n=s.size();
	for(int i=0;i<n;i++)
	{
		if(s[i]=='-')
		{
			b=i+1;
			break;
		}
	}
	a=b-1;
	c=n-b;
	if(a>1&&a<=8&&c>0&&c<=24)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}