题目:http://codeforces.com/problemset/problem/626/A
代码:
#include<stdio.h>
#include<string.h>
#include<string>
using namespace std;
int main()
{
int a;
while(~scanf("%d",&a))
{
char b[205];
scanf("%s",b);
int ans=0;
for(int i=0;i<a;i++)
{
int x=0,y=0;
for(int j=i;j<a;j++)
{
if(b[j]=='U')y++;
if(b[j]=='D')y--;
if(b[j]=='L')x--;
if(b[j]=='R')x++;
if(x==0&&y==0)ans++;
}
}
printf("%d\n",ans);
}
}
分析:
刚开始完全看不懂题,后来看的其他人的代码才看懂题意。学渣飘过~~~~。