当前位置:网站首页>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;
}
运行结果

边栏推荐
- Stringredistemplate disconnects and the value disappears
- Reading is the cheapest noble
- Resizekit2.net size and resolution independent
- How to deal with occasional bugs?
- Questions about database: database attachment
- I learned database at station B (V): DQL exercise
- In depth analysis of a large number of clos on the server_ The root of wait
- Online sql to CSV tool
- 【机器学习Q&A】余弦相似度、余弦距离、欧式距离以及机器学习中距离的含义
- “乘风破浪”的芒果超媒,能上岸吗?
猜你喜欢

Online sql to CSV tool

Seata 与三大平台携手编程之夏,百万奖金等你来拿

Ansible ad-hoc temporary command

2020-12-03

js内容混淆,返回内容加密

STC89C52 single chip microcomputer simple calculator design and code demonstration

81. search rotation sort array II

Kubernetes core object overview details

Preliminary understanding of NVIDIA Jetson nano

Newton method (optimization of two variable functions)
随机推荐
What if you can't write your composition well? Ape counseling: parents should pay attention to these points
ResizeKit2.NET大小和分辨率独立
The Web3 era is coming? Inventory of five Web3 representative projects | footprint analytics
快手伸手“供给侧”,找到直播电商的“源头活水”?
Cookie加密10
Three text to speech artifacts, each of which is very practical
JS recursive summation 1-100
C language final without failing (Part 1)
C language selection, loop overview
Cantilever beam calculation [matlab code]
Machinery -- nx2007 (UG) finite element analysis tutorial 2 -- assembly
【PyTorch实战】生成对抗网络GAN:生成动漫人物头像
[mrctf2020]ezpop-1 | PHP serialization
Difference between test plan and test plan
Reading is the cheapest noble
Cookie加密12
Seata 与三大平台携手编程之夏,百万奖金等你来拿
Quality management of functional modules of MES management system
Wechat applet - requestsubscribemessage:fail can only be invoked by user tap gesture
In depth analysis of a large number of clos on the server_ The root of wait