B - AcCepted

网址:https://abc104.contest.atcoder.jp/tasks/abc104_b

题目:

Time limit : 2sec / Memory limit : 1024MB

Score : 200 points

Problem Statement

You are given a string S. Each character of S is uppercase or lowercase English letter. Determine if S satisfies all of the following conditions:

  • The initial character of S is an uppercase A.
  • There is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive).
  • All letters except the A and C mentioned above are lowercase.

Constraints

  • 4≤|S|≤10 (|S| is the length of the string S.)
  • Each character of S is uppercase or lowercase English letter.
    #include<iostream>
    #include<string>
    #include<cstdio>
    using namespace std;
    int n1,t;
    int main()
    {
    	string c;
    	int len,f=1;
    	cin>>c;
     	len=c.length();
     	for(int i=0;i<len;i++)
      	{
      		if(c[i]!='A' && c[i]!='C')
    			if(isupper(c[i]))
    				f=0;
    	}
    	int count=0;
    	for(int i=2;i<len-1;i++)
       		if(c[i]=='C')  
    		   	count++;
    	if(count!=1)
    		f=0;
    	if(c[0]!='A')
    		f=0;
    	if(f==1)
    		cout<<"AC"<<endl;
    	else
    		cout<<"WA"<<endl;
      	return 0;
    }
    

    解法:首先考虑除了A,C外,是否还有大写字母,如果有,则排除这种情况

  • 二是寻找C存在的位置,根据题目已知它是在第三个字符和倒数第二个字符之间的(包含第三和倒数第二个字符)并且次数只能是1,所以这里用了一个count来计数,再判断第一个字符是否是A,就全面考虑了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值