其他分享
首页 > 其他分享> > Corporation Mail CodeForces - 56C

Corporation Mail CodeForces - 56C

作者:互联网

原题链接
考察:思维
思路:
  每一个.代表了一个\(boss\)下属关系的声明结束.对于每一个\(.\)对比最后一个字符串和前面所有储存的字符串,如果相同\(ans++\)

Code

#include <iostream> 
#include <cstring>
#include <string>
using namespace std;
const int N = 1010;
char s[N];
string str[N];
int n,cnt;
int main()
{
	scanf("%s",s);
	n = strlen(s);
	string t;
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		while(isalpha(s[i]))
		{
			t+=s[i];
			i++;
		}
		if(s[i]==':')
		{
			str[++cnt] = t;
			t = "";
		}
		if(s[i]==',') continue;
		if(s[i]=='.')
		{
			if(t!="") str[++cnt] = t;
			for(int j=1;j<cnt;j++)
			  if(str[j]==str[cnt]) ans++;
			cnt--;
			t = "";
		}
	}
	printf("%d\n",ans);
	return 0;
}

标签:include,string,原题,int,Corporation,CodeForces,ans,字符串,56C
来源: https://www.cnblogs.com/newblg/p/15291591.html