hdu 3788 ZOJ问题 Problem Description
对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC。
是否AC的规则如下:
1. zoj能AC;
2. 若字符串形式为xzojx,则也能AC,其中x可以是N个'o' 或者为空;
3. 若azbjc 能AC,则azbojac也能AC,其中a,b,c为N个'o'或者为空;
Input
输入包含多组测试用例,每行有一个只包含'z','o','j'三种字符的字符串,字符串长度小于等于1000;
Output
对于给定的字符串,如果能AC则请输出字符串“Accepted”,否则请输出“Wrong Answer”。
Sample Input
zoj
ozojo
ozoojoo
oozoojoooo
zooj
ozojo
oooozojo
zojoooo
Sample Output
Accepted
Accepted
Accepted
Accepted
Accepted
Accepted
Wrong Answer
Wrong Answer
*/
/*
解题分析:
处理策略:经过观察,发现a,b,c 存在一定的关系,即为c=a*b;
另外必须满足Z j只能一次,还必须出现。Z J中间的O
至少出现一次;
满足以上处理即可;
*/
#include<stdio.h>
#include<string.h>
int main()
{
char p[10010];
int a,b,c;
int d,e;
int i,j,k;
while(gets(p)!=NULL)
{
i=0;
a=0;
d=e=0;
while(p[i]!='z')
{
a++;
i++;
}
while(p[i]=='z')
{
d++;
i++;
}
b=0;
while(p[i]!='j')
{
b++;
i++;
}
while(p[i]=='j')
{
e++;
i++;
}
c=0;
while(p[i]!='\0')
{
c++;
i++;
}
if(d==1&&e==1&&b!=0)
{
if(c==a*b)
printf("Accepted\n");
else
printf("Wrong Answer\n");
}
else
printf("Wrong Answer\n");
}
return 0;
}
Problem Description
读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当某个字符用完时,剩下的仍然按照ZOJ的顺序输出。
Input
题目包含多组用例,每组用例占一行,包含ZOJ三个字符,当输入“E”时表示输入结束。
1<=length<=100。
Output
对于每组输入,请输出一行,表示按照要求处理后的字符串。
具体可见样例。
Sample Input
ZZOOOJJJ
ZZZZOOOOOJJJ
ZOOOJJ
E
Sample Output
ZOJZOJOJ
ZOJZOJZOJZOO
ZOJOJO
#include<stdio.h>
#include<string.h>
int main()
{
char p[10010];
int a,b,c;
int i,j;
while(gets(p)&&p[0]!='E')
{
i=0;
a=b=c=0;
while(p[i]!='\0')
{
if(p[i]=='Z')
{
a++;
i++;
continue;
}
if(p[i]=='O')
{
b++;
i++;
continue;
}
if(p[i]=='J')
{
c++;
i++;
continue;
}
}
while(a>0||b>0||c>0)
{
if(a>0)
printf("Z");
a--;
if(b>0)
printf("O");
b--;
if(c>0)
printf("J");
c--;
}
printf("\n");
}
return 0;
}