zoukankan      html  css  js  c++  java
  • 10324

    Problem N

    Zeros and Ones

    Input: standard input

    Output: standard output

    Time Limit: 2 seconds

    Memory Limit: 32 MB

    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.

     

    Sample Input

    0000011111
    3
    0 5
    4 2
    5 9
    01010101010101010101010101111111111111111111111111111111111110000000000000000
    5
    4 4
    25 60
    1 3
    62 76
    24 62
    1
    1
    0 0
     

    Sample Output

    Case 1:
    No
    Yes
    Yes
    Case 2:
    Yes
    Yes
    No
    Yes
    No
    Case 3:
    Yes
    #include<stdio.h>
    #include<string.h>
    #define max(a,b) a>b?a:b
    #define min(a,b) a<b?a:b
    char a[1000005];
    int check(int x,int y)
    {
    	int z;
    	for(z=x;z<=y;z++)
    		if(a[x]!=a[z])
    			return 0;
    	return 1;
    }
    int main()
    {
    	int n,i,j,k,count=1;
    	while(scanf("%s",a)!=EOF)
    	{
    		printf("Case %d:
    ",count++);
    		scanf("%d",&n);
    		for(k=0;k<n;k++)
    		{
    			scanf("%d%d",&i,&j);
    			if(check(min(i,j),max(i,j)))
    				puts("Yes");
    			else 
    				puts("No");
    		}
    	}
    	return 0;
    }
  • 相关阅读:
    MFC中char*,string和CString之间的转换(待补充)
    Gem/Bundle/Rvm
    Ruby开发入门
    Maven原型骨架及常见问题
    Nginx Upstream模块源码分析(上)
    mysqldump的几个主要选项探究
    探索Antlr(Antlr 3.0更新版)
    Maven2插件开发入门
    说说家乡的互联网-沈阳
    Nginx模块之SessionSticky
  • 原文地址:https://www.cnblogs.com/riskyer/p/3299479.html
Copyright © 2011-2022 走看看