HNUST 压缩编码
问题 D: Zeros and Ones
时间限制: 1 Sec 内存限制: 128 MB 提交: 43 解决: 18 [提交][状态][讨论版]题目描述
Consider strings of characters made up by concatenating any number of the strings 0, 01 or 11.
For example 00011111 is one such string, as is 001011, but 1011 is not. Your job is simply to determine if a given string can be constructed in this manner.
输入
There will be multiple problem sets. Input for each problem will be on one line. Each line (except
the last) will be of the form
n s
where n is a non-negative integer no larger than 100 and s is a string of 0’s and 1’s of length n.
A value of n = 0 indicates end of input.
输出
Each problem should generate one line of code, either,
String m can be generated.
or
String m can not be generated.
accordingly, where m is the number of the problem (stating at 1).
样例输入
8 00011111
6 001011
4 1011
0
样例输出
String 1 can be generated.
String 2 can be generated.
String 3 can not be generated.
1 #include <cstdio> 2 #include <iostream> 3 #include <vector> 4 #include <set> 5 #include <cstring> 6 #include <string> 7 #include <map> 8 #include <cmath> 9 #include <ctime> 10 #include <algorithm> 11 #include <queue> 12 13 using namespace std; 14 #define INF 0x7fffffff 15 #define mod 1000000007 16 #define maxm 1001 17 #define mp make_pair 18 #define pb push_back 19 #define rep(i,n) for(int i = 0; i < (n); i++) 20 #define re return 21 #define fi first 22 #define se second 23 #define sz(x) ((int) (x).size()) 24 #define all(x) (x).begin(), (x).end() 25 #define sqr(x) ((x) * (x)) 26 #define sqrt(x) sqrt(abs(x)) 27 #define y0 y3487465 28 //#define y1 y8687969 29 #define fill(x,y) memset(x,y,sizeof(x)) 30 31 typedef vector<int> vi; 32 typedef long long ll; 33 typedef long double ld; 34 typedef double D; 35 typedef pair<int, int> ii; 36 typedef vector<ii> vii; 37 typedef vector<string> vs; 38 typedef vector<vi> vvi; 39 40 template<class T> T abs(T x) { re x > 0 ? x : -x; } 41 42 const int maxn = 110005; 43 int n, m, t, k, ans; 44 ll x, y; 45 //string s; 46 ll p1[maxn], p2[maxn]; 47 int a[maxn]; 48 char s[maxn]; 49 int main(){ 50 int cas = 1; 51 while (scanf("%lld", &n)&&n){ 52 scanf("%s", s); 53 x = 0; 54 for (int i = 0; i < strlen(s); i++) 55 if (s[i] == '1')x++; 56 else break; 57 if (x & 1)printf("String %d can not be generated.\n",cas++); 58 else printf("String %d can be generated.\n",cas++); 59 } 60 return 0; 61 }
浙公网安备 33010602011771号