1412091645-hd-ZOJ

ZOJ

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1899    Accepted Submission(s): 1344

Problem Description

读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当某个字符用完时,剩下的仍然按照ZOJ的顺序输出。

Input

题目包含多组用例,每组用例占一行,包含ZOJ三个字符,当输入“E”时表示输入结束。

1<=length<=100。

Output

对于每组输入,请输出一行,表示按照要求处理后的字符串。

具体可见样例。

Sample Input

ZZOOOJJJ
ZZZZOOOOOJJJ
ZOOOJJ
E

Sample Output

ZOJZOJOJ
ZOJZOJZOJZOO
ZOJOJO

解题思路

确定Z、O、J的数量。然后循环判断,数量不为0就输出,循环len次。

代码

#include<stdio.h>
#include<string.h>
char zoj[110];
int main()
{
	int len;
	int i,j,k;
	int numz,numo,numj;
	while(scanf("%s",zoj)&&strcmp("E",zoj)!=0)
	{
		len=strlen(zoj);
		numz=numo=numj=0;
		for(i=0;i<len;i++)
		{
			if(zoj[i]=='Z')
			    numz++;
			else if(zoj[i]=='O')
			    numo++;
			else
			    numj++;
		}
		while(len--)
		{
			if(numz!=0)//数量不为0就输出,为0就跳过
			{
				printf("Z");
				numz--;
			}
			if(numo!=0)
			{
				printf("O");
				numo--;
			}
			if(numj!=0)
			{
				printf("J");
				numj--;
			}
		}
		printf("\n");
	}
	return 0;
} 
时间: 2024-08-12 22:05:29

1412091645-hd-ZOJ的相关文章

zoj 1649

//hnldyhy(303882171) 11:12:46// zoj 1649 //bfs +优先队列 #include <stdio.h>#include <iostream>#include <queue>using namespace std;struct node{ int x; int y; int step;}; bool operator<(const node &a,const node &b){ if (a.step>b.

ZOJ 3203 Light Bulb (三分+计算几何)

题目地址:ZOJ 3203 第一发三分.三分的原理还是挺简单的. 代码如下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib.h> #include <map> #include <set> #include <stdio.h&g

ZOJ 3203 Light Bulb 三分

最简单的三分题,期末考完先做一道练练手 就是这么一个图,告诉你H h D,问你L最长是多少,假设人到灯的距离是X,那么容易得到 L = H-D/x*(H-h)+D-x,求个导很容易发现是一个关于x 的凸性函数,就可以三分啦 要注意的是三分的时候的精度eps,这题要求得是1e-9才能A,1e-8都WA,真是囧 #include <cstdio> #include <sstream> #include <fstream> #include <cstring> #

zoj 3790 Consecutive Blocks(链表重点是思想)

Consecutive Blocks Time Limit: 2 Seconds      Memory Limit: 65536 KB There are N (1 ≤ N ≤ 105) colored blocks (numbered 1 to N from left to right) which are lined up in a row. And the i-th block's color is Ci (1 ≤ Ci ≤ 109). Now you can remove at mos

概率dp ZOJ 3640

Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3640 Appoint description:  System Crawler  (2014-10-22) Description Background     If thou doest well, shalt thou not be accepted? an

zoj 2156 - Charlie&#39;s Change

题目:钱数拼凑,面值为1,5,10,25,求组成n面值的最大钱币数. 分析:dp,01背包.需要进行二进制拆分,否则TLE,利用数组记录每种硬币的个数,方便更新. 写了一个 多重背包的 O(NV)反而没有拆分快.囧,最后利用了状态压缩优化 90ms: 把 1 cents 的最后处理,其他都除以5,状态就少了5倍了. 说明:貌似我的比大黄的快.(2011-09-26 12:49). #include <stdio.h> #include <stdlib.h> #include <

ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 最小生成树 Kruskal算法

题目链接:ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 Building a Space Station Time Limit: 2 Seconds      Memory Limit: 65536 KB You are a member of the space station engineering team, and are assigned a task in the construction process of the statio

ZOJ 3607 Lazier Salesgirl (贪心)

Lazier Salesgirl Time Limit: 2 Seconds      Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling. She can sell the i-th customer a piece of bread for price pi. But she is so lazy

ZOJ - 2243 - Binary Search Heap Construction

先上题目: Binary Search Heap Construction Time Limit: 5 Seconds      Memory Limit: 32768 KB Read the statement of problem G for the definitions concerning trees. In the following we define the basic terminology of heaps. A heap is a tree whose internal n

ZOJ 2859 二维线段树

思路:自己写的第二发二维线段树1A,哈哈,看来对二维的push操作比较了解了:但是还没遇到在两个线段树中同时进行push操作的,其实这题我是想在x维和y维同时进行push操作的,但是想了好久不会,然后看到这题又给出10秒,然后想想在x维线段直接单点查询肯定也过了,然后在第二维就只有pushup操作,在第一维线段树没有pushup操作.要是在第一维也有pushup操作的话,那就不用单点查询那么慢了.不过也A了,想找题即在二维同时进行pushup和pushdown操作的. #include<iost