PAT-1003-我要通过

7-8月是我的低产期.

7月份上旬小学期学习JAVA做网站, 7月下旬和8月上旬开始刷书 C++ primer 第五版.

发现原来所谓上课讲的C++真的离真正的C++差远了!!!

毕竟原来那本书叫 C++面向对象编程.... 而自己一直在用C++写C的语法..

所以接下来的程序就会尽可能的参考C++ primer按照C++的思想和语法习惯来编程~

争取8-31能考出PAT证书来!!!!

加油!!!!!

 

String.size() 这个类型返回的类型是: std::string::size_type, 它的定义是 unsigned int

C++中的编程习惯要求: for循环使用 != 而不是 <=  或 >=

C++中的编程习惯要求: 自增尽量写 ++X, 而不是X++

另外, 关于NULL, 在C语言中, 声明C指针时候经常用NULL,

但是在C++ 11标准中, 用nullptr;

过去的程序还会用到一个名为NULL的预处理变量(preprocessor variable)来给指针赋值, 这个变量在头文件cstdlib中定义, 它的值就是0;

而stddef.h中定义的宏如下:

/* A null pointer constant.  */

#if defined (_STDDEF_H) || defined (__need_NULL)
#undef NULL		/* in case <stdio.h> has defined it. */
#ifdef __GNUG__
#define NULL __null
#else   /* G++ */
#ifndef __cplusplus
#define NULL ((void *)0)
#else   /* C++ */
#define NULL 0
#endif  /* C++ */
#endif  /* G++ */
#endif	/* NULL not defined and <stddef.h> or need NULL.  */
#undef	__need_NULL
#include <iostream>
#include "stddef.h"

using namespace std;

const int str_size = 10;
typedef string::size_type st;

bool check(string str){
    st location_P=0, location_T=0;
    st count_P=0,count_T=0;
    st mid_A=0, front_A=0, behind_A=0;
    for(st i=0; i!=str.size(); ++i){
        if(str[i]!='P' && str[i]!='A' && str[i]!='T'){
            return false;
        }
        if(str[i]=='P'){
            location_P = i;
            ++count_P;
        }
        if(str[i]=='T'){
            location_T = i;
            ++count_T;
        }
    }
    mid_A = location_T - location_P - 1;
    front_A = location_P;
    behind_A = str.size() - location_T - 1;
    if(count_P!=1 || count_T!=1 || mid_A==0){
        return false;
    }
    if(behind_A==front_A * mid_A){
        return true;
    }
    return false;
}

int main()
{
    string str[str_size];
    int n;
    cin >> n;
    for(int i=0; i!=n; ++i){
        cin>>str[i];
    }
    for(int i=0; i!=n; ++i){
        if(check(str[i])){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值