当前位置:网站首页>C语言 我要通过
C语言 我要通过
2022-06-30 01:25:00 【Martin の Blog】

算法设计思路
- 首先,输入的样例中如果有除了PAT其余的字符,程序视为NO
- 其次,对于 “aPbATca” 当 ‘c’ 和 ‘a’ 均为空字符,‘b’ 是 ‘A’ 字符,则可以判断:“PAAT” 是正确的
- 最后 ,其余的字符判断可以进行公式推论:P前面A的数量 * P和T中间A的数量 = T之后A的数量,如果满足这个公式也是对的
- 结合上诉思路开始代码的实现
代码
#include <stdio.h>
int main(){
char a[10][100] = {
0};
int n,i,j,count_A,count_P,count_T,s1,s2,s3;
scanf("%d", &n);
for(i=0; i<n; i++){
scanf("%s", &a[i]);
}
for(i=0; i<n; i++){
j=0, count_A=0, count_P=0, count_T=0, s1=0, s2=0, s3=0;
while(a[i][j] != '\0'){
if(a[i][j]=='A'){
count_A++;
}else if(a[i][j]=='P'){
count_P++;
s1 = j;
}else if(a[i][j]=='T'){
count_T++;
s2 = j;
}else{
s3 = 1;
break;
}
j++;
}
if(s3!=1 && count_P==1 && count_T==1 && !((s2-s1-1)*s1-(count_A-s2+1)) && (s2-s1-1)){
printf("YES");
}else{
printf("NO");
}
if(i != n-1){
printf("\n");
}
}
return 0;
}
运行结果

边栏推荐
- Interview summary
- cookie加密8
- 【图神经网络】图分类学习研究综述[2]:基于图神经网络的图分类
- JS prototype and prototype chain (Lantern Festival meal)
- Quick pow: how to quickly find power
- Seata 与三大平台携手编程之夏,百万奖金等你来拿
- Error reporting in Luban H5 installation
- Seata and the three platforms are working together in the summer of programming. Millions of bonuses are waiting for you
- Ctfshow competition original title 680-695
- [mrctf2020]ezpop-1 | PHP serialization
猜你喜欢

Some thoughts on small program subcontracting and verification of uiniapp subcontracting optimization logic

Cookie加密15 登录加密

81. 搜索旋转排序数组 II

浅析现代Web端im即时通讯开发技术

How to seamlessly transition from traditional microservice framework to service grid ASM

首届·技术播客月开播在即

Application of pointer in STC89C52 single chip microcomputer and demonstration of practical cases

【论文写作】英文论文写作指南

Preliminary understanding of NVIDIA Jetson nano

ES6 one line code for array de duplication
随机推荐
Can mango hypermedia, which "braves the wind and waves", go ashore?
Ansible ad-hoc 临时命令
Cookie加密12
How to deal with occasional bugs?
英伟达Jetson Nano的初步了解
RubyMine开发工具,重构和意图操作
Kubernetes 核心对象概览详解
Mysql 监控3
Solution to webkitformboundaryk in post request
Sentinel source code analysis Part 8 - core process - sphu Entry current limiting execution
JS prototype and prototype chain (Lantern Festival meal)
Stimulus reports reporting tool, stimulus creates and builds reports
[535. encryption and decryption of tinyurl]
ES6 one line code for array de duplication
Mysql 监控2
js内容混淆,返回内容加密
Kubernetes core object overview details
The first unlucky person watching eth 2.0
Pytroch Learning Notes 6: NN network layer convolution layer
Interface Association of postman