D - アンバランス / Unbalanced

Problem Statement

Given a string tt, we will call it unbalanced if and only if the length of tt is at least 22, and more than half of the letters in tt are the same. For example, both voodoo and melee are unbalanced, while neither noon nor a is.

You are given a string ss consisting of lowercase letters. Determine if there exists a (contiguous) substring of ss that is unbalanced. If the answer is positive, show a position where such a substring occurs in ss.

Constraints

  • 2≦|s|≦1052≦|s|≦105
  • ss consists of lowercase letters.

Partial Score

  • 200200 points will be awarded for passing the test set satisfying 2≦N≦1002≦N≦100.

Input

The input is given from Standard Input in the following format:

ss

Output

If there exists no unbalanced substring of ss, print -1 -1.

If there exists an unbalanced substring of ss, let one such substring be sasa+1...sbsasa+1...sb (1≦a<b≦|s|)(1≦a<b≦|s|), and print \(a\) \(b\). If there exists more than one such substring, any of them will be accepted.


Sample Input 1 Copy

Copy

needed

Sample Output 1 Copy

Copy

2 5

The string s2s3s4s5s2s3s4s5 == eede is unbalanced. There are also other unbalanced substrings. For example, the output 2 6 will also be accepted.


Sample Input 2 Copy

Copy

atcoder

Sample Output 2 Copy

Copy

-1 -1

The string atcoder contains no unbalanced substring.

题意:
给定一个字符串让你找其中的一个不平衡子串(不平衡子串是某一个字符出现的次数超过该子串长度的一半)

题解:

若存在的话一定存在xx或x_x的情况。否则一定不存在,可以试着举例试试。

代码:
 

#include<bits/stdc++.h>
using namespace std;
char st[100009];
int main()
{
    scanf("%s",st+1);
      int len=strlen(st+1);

       for(int i=1;i<=len;i++)
       {
           if(i+1<=len&&st[i+1]==st[i])
           {
               cout<<i<<" "<<i+1<<endl;
               return 0;
           }
           if(i+2<=len&&st[i+2]==st[i])
           {
               cout<<i<<" "<<i+2<<endl;
               return 0;
           }
       }
       cout<<"-1 -1"<<endl;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值