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>
- UVa:10324 - Zeros and Ones
- UVa -- 10324 Zeros and Ones
- UVa 10324 - Zeros and Ones
- UVA - 10324 Zeros and Ones
- Zeros and Ones UVA
- 10324 - Zeros and Ones
- Ones and Zeros
- Zeros and Ones
- UVa10324 - Zeros and Ones
- Zeros and Ones
- the Zeros and Ones
- [leetcode]ones and zeros
- uva 12063 Zeros and Ones dp记忆化
- TOJ 3519.Ones and Zeros
- [UVA12063] Zeros and Ones && 数位DP
- A. Case of the Zeros and Ones
- A. Case of the Zeros and Ones
- Case of the Zeros and Ones
- 预加载图片
- debian下安装fctix却无法使用
- fsdfdsfsdf
- (经过试验)我的驱动和程序共享内存代码
- android 主线程和子线程之间的消息传递
- UVa -- 10324 Zeros and Ones
- jquery error: 200
- HDU3847 Trash Removal(凸包)
- windows游戏编程<七> 创建WIN32一个HelloWOrld程序
- ffmpeg+sdl2.0做一个简单的音频播放器
- Transfer postgres database to another server - backup and restore
- Spring 基础教程之五:AOP编程介绍
- URL和URI的区别和联系
- 绝对路径和相对路径的区别