UVa -- 10324 Zeros and Ones

来源:互联网 发布:哈萨克歌软件 编辑:程序博客网 时间:2024/05/22 08:02

Description

Given a string of 0's and 1's up to 1000000 characters long and indices i and j, you are to answer a question whether all characters between position min(i,j) and position max(i,j) (inclusive) are the same.

Input

There are multiple cases on input. The first line of each case gives a string of 0's and 1's. The next line contains a positive integer n giving the number of queries for this case. The next n lines contain queries, one per line. Each query is given by two non-negative integers, i and j. For each query, you are to print Yes if all characters in the string between position min(i,j) and position max(i,j) are the same, and No otherwise.

Output

Each case on output should start with a heading as in the sample below. The input ends with an empty string that is a line containing only the new line character, this string should not be processed. The input may also with end of file. So keep check for both.

<span style="font-size:14px;">#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxn=1000100;char f[maxn];int s[maxn];int interval_sum(int i, int j){    if(i>j) swap(i,j);    if(s[j]-s[i-1]==j-i+1||s[j]-s[i-1]==0)        printf("Yes\n");    else printf("No\n");}int main(){    int a,b,n,cnt=0;    while(scanf("%s",f)==1){        cnt++;        memset(s,0,sizeof(s));        int l=strlen(f);        s[0]=f[0]-'0';        for(int i=1;i<l;i++)            s[i]=s[i-1]+(f[i]-'0');        printf("Case %d:\n",cnt);        scanf("%d",&n);        for(int h=0;h<n;h++){            scanf("%d%d",&a,&b);            interval_sum(a,b);        }    }    return 0;}</span>
<span style="font-size:14px;">#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxn=1000100;char f[maxn];int main(){    int a,b,n,cnt=1;    while(scanf("%s",f)==1){        printf("Case %d:\n",cnt);        scanf("%d",&n);        for(int h=0;h<n;h++){            scanf("%d%d",&a,&b);            int temp,flog=0;            if(a>b) swap(a,b);            for(int i=a;i<=b;i++){                if(f[i]!=f[a]){                    flog=1;                    break;                }            }            if(flog)                printf("No\n");            else printf("Yes\n");        }    cnt++;    }    return 0;}</span>



0 0
原创粉丝点击