看到就烦啊 题目这么长
参考别人的代码。。暴力过的 数据太小
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
char tm[55][55];
struct position
{
int x,y;
};
position pos[55*55+5];
int main()
{
string s;
int n,i,j;
cin>>n;
getchar();
int copn=n;
for (i=1;i<=n;i++)
gets(tm[i]+1);
n=copn;
int ok=0;
s+='0';
for (i=1;i<=n;i++)
{
for (j=1;j<=strlen(tm[i]+1);j++)
{
s+=tm[i][j];
pos[++ok].x=i;
pos[ok].y=j;
}
}
for( i=1;i<s.size();i++)
{
if(s[i]<='z'&&s[i]>='a')
{
int flag=0;//记录是否隐藏了nearnest
int ans=0; //记录是否遇到“{}”
for (j=i-1;j>=1;j--)
{
if (ans==0&&s[j]==s[i]) //如果ans==0即"相当于"j与i的关系是nearnest
{
printf("%d:%d: warning: shadowed declaration of %c, the shadowed position is %d:%d\n",pos[i].x,pos[i].y,s[i],pos[j].x,pos[j].y);
flag=1; //只隐藏nearest的变量;
}
if (flag)
break;
if (s[j]=='}')
ans++;
if (s[j]=='{'&&ans>0) // 在ans==0时遇到{不影响,而ans>0意味着先遇到了} 若遇到了}右边的变量 并不是nearest,需要再遇到{左边的才是
ans--;
}
}
}
return 0;
}