980A Links and Pearls

A. Links and Pearls
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

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).

Examples
input
Copy
-o-o--
output
Copy
YES
input
Copy
-o---
output
Copy
YES
input
Copy
-o---o-
output
Copy
NO
input
Copy
ooo
output
Copy
YES


题意:输入一串字符,O表示珍珠,-表示线,你可以移除珍珠和线,然后重新连接,可以无限次操作。最后连接出来的时候,每两个珍珠之间的线是否一样,一样就输出YES,否则就输出No。(题目最后更新了题意,全是线或者珍珠都输出YES


题解: 特判全为线和全珍珠的情况,输出YES。一个珍珠也是YES,其余情况如果线是珍珠的倍数,也是YES,其余就是NO。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int a=0,b=0;
    for(int i=0; i<s.size(); i++)
        if(s[i]=='-') a++;
        else b++;
        if(!b||!a||b==1||a%b==0)
            puts("YES");
        else puts("NO");
    return 0;
}


猜你喜欢

转载自blog.csdn.net/memory_qianxiao/article/details/80258049