PAT——乙级真题1003代码
2015-11-09 17:34
309 查看
#include<iostream> #include<string> using namespace std; int getLength(string str0); int main(){ int n, index=0; cin>>n; //define dynamic array string *str=new string ; //initialize the array for(int i=0;i<n;i++){ cin>>str[i]; } //deal with the data for(int j=0;j<n;j++){ int posp=-1, post=-1, nump=0, numt=0, ok=0,firstA=0, mediumA=0, lastA=0, other=0; string pat=str[j]; int len=getLength(pat); for(int n=0;n<len;n++){ if(pat =='P'){ posp=n; nump++; }else if(pat =='T'){ post=n; numt++; }else if(pat !='A'&&pat !=' ') other++; } if(other==0&&nump==1&&numt==1&&post>posp){ firstA=posp; mediumA=post-posp-1; lastA=len-post-1; if(firstA==0&&lastA==0&&mediumA>=1)ok=1; if(firstA>0&&lastA>0&&lastA==firstA*mediumA)ok=1; if(ok==0)cout<<"NO"<<endl; else cout<<"YES"<<endl; }else cout<<"NO"<<endl; } return 0; } int getLength(string str0){ int i=0; while (str0[i]!='\0')i++; return i; }
相关文章推荐
- C语言调用Python函数
- 编程之美-最大公约数问题方法整理
- java调用url的两种方式
- Spring下载
- MyEclipse中的两种FreeMarker插件的安装与配置
- 正则表达式preg_replace学习
- Java并发集合的实现原理
- 关于c++顺序容器小结(一)---概述
- .NET异步编程:IO完成端口与BeginRead
- asp.net试题解析
- 详解spring事务属性
- WritePrivateProfileString GetPrivateProfileString 读取写 配置文件
- java的HashCode方法
- Java基础之理解Annotation
- php7 性能测试
- Python嵌入C/C++ (Python核心编程)
- Java并发编程(五) 任务的取消
- Spring bean 通过实现 InitializingBean ,DisposableBean 接口实现初始化方法和销毁前操作
- php 5.6.14手动安装 php -v 显示没有安装
- c++ 智能指针用法详解