A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one.
You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you like, but you can't throw away any parts.
Can you make the number of links between every two adjacent pearls equal? Two pearls are considered to be adjacent if there is no other pearl between them.
Note that the final necklace should remain as one circular part of the same length as the initial necklace.
The only line of input contains a string ss (3≤|s|≤1003≤|s|≤100), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl.
Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO".
You can print each letter in any case (upper or lower).
-o-o--
YES
-o---
YES
-o---o-
NO
ooo
YES
题意:现在有一个环形项链,‘-’代表连接的链,‘o’代表珍珠,现在你可以随意拆,随意组装,只能使用现有的-和o,不可以丢掉,能否组合成:每个珍珠之间的链的长度都相等。
思路:因为是环,所以有几个珍珠,就必然有几个间隔,这些间隔内的链长都相等,即链的总数整除珍珠总数即可YES,否则NO。
ps:有个特判,题目公告有说,没有珍珠的话,判定为YES。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#define ll long long
#define exp 1e-8
#define mst(a,k) memset(a,k,sizeof(a))
using namespace std;
char s[110];
int main()
{
while(~scanf("%s",s+1))
{
ll len=strlen(s+1);
ll ans1=0,ans2=0;
for(ll i=1;i<=len;i++)
{
if(s[i]=='o')ans1++;
else ans2++;
}
if(ans1==0){printf("YES\n");continue;} //特判
if(ans2%ans1==0)printf("YES\n");
else printf("NO\n");
}
return 0;
}