Codeforces 980A Links and Pearls(瞎搞)

题意

给定一个只包含 -o 的字符串,- 表示项链上的链,o 表示项链上的珍珠,将字符串首尾相连表示一条项链,每次操作可以将任意位置的链或珍珠拆下,插入到另一个位置上,问进行任意多次操作后,能否使得项链上任意两个相邻的珍珠之间的链的数量相等。

输入

输入为一个字符串 s (3|s|100) s   ( 3 ≤ | s | ≤ 100 ) ,字符串只包含字符 -o

输出

如果可以,则输出 YES Y E S ,否则输出 NO N O ,大小写任意。

样例

输入
-o-o--
输出
YES
输入
-o---
输出
YES
输入
-o---o-
输出
NO
输入
ooo
输出
YES
题解

计算项链上 o 的数量 cnto c n t o - 的数量 cnt c n t − ,满足 cnt c n t − cnto c n t o 的倍数或者 cnto c n t o 的数量为 0 0 ,就输出 YES,否则输出 NO N O

过题代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
using namespace std;

#define LL long long
const int maxn = 100 + 100;
int cnt1, cnt2;
char str[maxn];

int main() {
    #ifdef LOCAL
    freopen("test.txt", "r", stdin);
//    freopen("testout.txt", "w", stdout);
    #endif // LOCAL
    ios::sync_with_stdio(false);

    while(scanf("%s", str) != EOF) {
        cnt1 = cnt2 = 0;
        for(int i = 0; str[i]; ++i) {
            if(str[i] == 'o') {
                ++cnt1;
            } else {
                ++cnt2;
            }
        }
        if(cnt1 == 0) {
            printf("YES\n");
            continue;
        }
        if(cnt2 % cnt1 == 0) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值