Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
SothicT
algorithm
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
algorithm
/
我要通过(20)2019_2_20.cpp
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
71 lines (67 loc) · 1.62 KB
master
Breadcrumbs
algorithm
/
我要通过(20)2019_2_20.cpp
Copy path
Top
File metadata and controls
Code
Blame
71 lines (67 loc) · 1.62 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
得到“答案正确”的条件是:
1. 字符串中必须仅有P, A, T这三种字符,不可以包含其它字符;
2. 任意形如 xPATx 的字符串都可以获得“答案正确”,其中 x 或者是空字符串,或者是仅由字母 A 组成的字符串;
3. 如果 aPbTc 是正确的,那么 aPbATca 也是正确的,其中 a, b, c 均或者是空字符串,或者是仅由字母 A 组成的字符串。
现在就请你为PAT写一个自动裁判程序,判定哪些字符串是可以获得“答案正确”的。
输入描述:
每个测试输入包含1个测试用例。第1行给出一个自然数n (<10),是需要检测的字符串个数。接下来每个字符串占一行,字符串长度不超过100,且不包含空格。
输出描述:
每个字符串的检测结果占一行,如果该字符串可以获得“答案正确”,则输出YES,否则输出NO。
*/
/*
具体思路:
(1)分别记录P,A,T的数量,以及第一次出现P和T的位置
(2)第一个条件:判断(P、A、T)数量之和是否为str总长
(3)
*/
#
include
<
stdio.h
>
#
include
<
iostream
>
#
include
<
string.h
>
using
namespace
std
;
int
main
(
void
)
{
int
n,i,j,len;
char
str[
101
] = {
0
};
string result[
10
];
int
count_p=
0
,count_a=
0
,
count_t
=
0
;
int
pos_p=
0
,
pos_t
=
0
;
cin>>n;
for
(i =
0
; i < n ; i++)
{
cin>>str;
count_p=
0
,count_a=
0
,
count_t
=
0
,pos_p=
0
,
pos_t
=
0
;
len =
strlen
(str);
for
(j =
0
; j < len ; j++)
{
if
(str[j] ==
'
P
'
)
{
count_p++;
pos_p = j;
}
if
(str[j] ==
'
A
'
)
{
count_a++;
}
if
(str[j] ==
'
T
'
)
{
count_t
++;
pos_t
= j;
}
}
if
((count_p+count_a+
count_t
) != len || count_p >
1
||
count_t
>
1
|| (
pos_t
-pos_p) >
2
|| pos_p*(
pos_t
-pos_p-
1
) != (len-
pos_t
-
1
))
{
result[i] =
"
NO
"
;
}
else
{
result[i] =
"
YES
"
;
}
}
for
(i =
0
; i < n ; i++ )
{
cout<<result[i]<<endl;
}
return
0
;
}
You can’t perform that action at this time.