K.Teamnames[ICPC Greater New York Region 2019][输入里有空格用getline(cin,str)]

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 1:

Stevens-1

YES

Sample 2:

INSTITUTION-TEAMNAME

NO

Sample 3:

Dragons

NO

Sample 4:

VIRGTECH - Eagles

NO

“Please note that spaces are counted as characters.”

空格也可以作为字符输入!!!

ac代码:

#include<iostream>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<vector>
#include<queue>
#include<array>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
const int mod=10^9+7;
//tuple<int,int,int>p[100000]
int main()
{
    string a;
    getline(cin,a);
    int len=a.size();
   // cout<<len<<endl;
    int ins=0;
    int group=0;
    for(int i=0;i<len;i++)
    {
        if(a[i]=='-')
        {
            ins=i;
            break;
        }
    }
    //cout<<ins<<endl;
    group=len-ins-1;
    //cout<<group<<endl;
    if((ins>1&&ins<=8)&&(group>=1&&group<=24))
        cout<<"YES";
    else
        cout<<"NO";
    return 0;
}

错误代码:

#include<iostream>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<vector>
#include<queue>
#include<array>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
const int mod=10^9+7;
//tuple<int,int,int>p[100000]
int main()
{
    string a;
    cin>>a;
    int len=a.size();
   // cout<<len<<endl;
    int ins=0;
    int group=0;
    for(int i=0;i<len;i++)
    {
        if(a[i]=='-')
        {
            ins=i;
            break;
        }
    }
    //cout<<ins<<endl;
    group=len-ins-1;
    //cout<<group<<endl;
    if((ins>1&&ins<=8)&&(group>=1&&group<=24))
        cout<<"YES";
    else
        cout<<"NO";
    return 0;
}

把cin换成getline就对了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值