Codeforces Round #410 (Div. 2)-A - Mike and palindrome

题目简述:给定一个字符串判断是否能够恰好改变一个字符使其变成回文(回文:eg.abcba或abccba)。

注意:1,是恰好改变一个字符,恰好!

2,字符串例如“abc”这样的奇数个数的而且是完整回文的字符串也是可以恰好改变一个字符变成回文的(改变最中间的那个字符,中间的那个字符改成什么都是回文)

我当时就卡死在这个坑。

我的代码是用栈做的虽然有点蠢...当时我都不知道for居然可以放两个入口变量,那样的话i++,j--就成了,我着急直接用栈,我居然不知道栈没有迭代器,也没注意上述注意事项2,结果就gg了。

那种简洁的做法我就不写了。

代码如下:

@font-face { font-family: "Times New Roman"; }@font-face { font-family: "宋体"; }@font-face { font-family: "Calibri"; }p.MsoNormal { margin: 0pt 0pt 0.0001pt; text-align: justify; font-family: Calibri; font-size: 10.5pt; }span.msoIns { text-decoration: underline; color: blue; }span.msoDel { text-decoration: line-through; color: red; }div.Section0 { }

#include<bits/stdc++.h>

using namespace std;

int main(){

stack<char> st;

char c[100];

int d_num;

while(gets(c)){

d_num=0;

if(strlen(c)<1){

cout<<"NO"<<endl;

continue;

}

for(int i=0;i<strlen(c);i++){

st.push(c[i]);

}

for(int i=0;i<strlen(c);i++){

if(c[i]!=st.top())  d_num++;

st.pop();

}

if((strlen(c)%2)&&d_num==0)  d_num+=2;

if(d_num==2)  cout<<"YES"<<endl;

else  cout<<"NO"<<endl;

}

return 0;

}

时间: 2024-10-23 11:08:43

Codeforces Round #410 (Div. 2)-A - Mike and palindrome的相关文章

Codeforces Round #410 (Div. 2)C. Mike and gcd problem(数论)

传送门 Description Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. . Mike wants to change his sequence in order to make it beautiful.

[卿学姐带飞系列]-Codeforces Round #410 (Div. 2)_B - Mike and strings

1 #include<bits/stdc++.h> 2 #define inf 0x3f3f3f3f 3 using namespace std; 4 const int maxn=55; 5 string s[maxn]; 6 int main() 7 { 8 int n; 9 cin>>n; 10 for(int i=0;i<n;i++){ 11 cin>>s[i]; 12 } 13 int ans=inf,tem; 14 for(int i=0;i<s

暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun

题目传送门 1 /* 2 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <iostream> 7 #include <algorithm> 8 #include <string> 9 using namespace std; 10 11 const int MAXN = 5e2 + 10; 12 const int

set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet

题目传送门 1 /* 2 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 3 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 4 查找左右相邻的位置,更新长度为r - l - 1的最大值,感觉线段树结构体封装不错! 5 详细解释:http://blog.csdn.net/u010660276/article/details/46045777 6 其实还有其他解法,先掌握这种:) 7 */ 8 #include <cstd

数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog

题目传送门 1 /* 2 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 3 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 4 详细解释:http://blog.csdn.net/u014357885/article/details/46044287 5 */ 6 #include <cstdio> 7 #include <algorithm> 8 #include <cstring> 9 #in

字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax

题目传送门 1 /* 2 字符串处理:回文串是串联的,一个一个判断 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <iostream> 7 #include <algorithm> 8 #include <string> 9 using namespace std; 10 11 const int MAXN = 1e3 + 10; 12 const int INF = 0x3f3

Codeforces Round #305 (Div. 1) B. Mike and Feet

Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high. A group of bears

Codeforces Round #305 (Div. 2) C. Mike and Frog +B. Mike and Fun

Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar. So, if height of Xaniar is h1 and height of Abol is 

Codeforces Round #410 (Div. 2) 解题报告

A. 因为A的题意导致这次罚时比较多--注意change一定是必须得改成不一样的,如a改成a是不行的. 1 #include <iostream> 2 #include <string> 3 #include <algorithm> 4 #include <cstring> 5 #include <cstdio> 6 #include <cmath> 7 #include <queue> 8 #include <se