2015
04-13

Is It Symmetric

It is easy to see that a string of digits like 1234321 is symmetric with 4 being the central digit. However it is less obvious if we consider the string as a circular one and shift it to the left as 2343211. Your task is to write a program to check if a circular string is symmetric.

The input file consists of several test cases. Each case occupies a line which contains the string. Each string contains less than 100 digits.
The input is finished by a "#".

The input file consists of several test cases. Each case occupies a line which contains the string. Each string contains less than 100 digits.
The input is finished by a "#".

2112343
798
#

YES 5
NO

#include<iostream>
using namespace std;
int main()
{
char s[105];
int i,j,n,l,r,flag;
while(cin>>s)
{
if(!strcmp(s,"#"))return 0;
n=strlen(s);
for(i=0;i<n;i++)
{
flag=0;
l=r=i;
while(s[l]==s[r])
{
l=(l-1+n)%n;
r=(r+1)%n;
if(l==r)
{
flag=1;
break;
}
}
if(flag)break;

}
if(flag)cout<<"YES "<<i<<endl;
else
cout<<"NO\n";

}
return 0;
}

1. 嗯 分析得很到位，确实用模板编程能让面试官对你的印象更好。在设置辅助栈的时候可以这样：push时，比较要push的elem和辅助栈的栈顶，elem<=min.top()，则min.push(elem).否则只要push（elem）就好。在pop的时候，比较stack.top()与min.top(),if(stack.top()<=min.top()),则{stack.pop();min.pop();}，否则{stack.pop();}.

2. 第2题，TCP不支持多播，多播和广播仅应用于UDP。所以B选项是不对的。第2题，TCP不支持多播，多播和广播仅应用于UDP。所以B选项是不对的。

3. 您没有考虑 树的根节点是负数的情况， 若树的根节点是个很大的负数，那么就要考虑过不过另外一边子树了