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

MY:(OUTPUT LIMIT EXCEED)

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<ctime>
#include<algorithm>
#include<cmath>
//#include<stack>
#define R(a,b,c) for(register int (a)=(b);(a)<=(c);++(a))
#define nR(a,b,c) for(register int (a)=(b);(a)>=(c);--(a))
#define Ii inline int
#define Il inline long long
#define Iv inline void
#define Id inline double
#define Ib inline bool
#define ll long long
#define re register
#define Fill(a,b) memset((a),(b),sizeof((a)))
#define Cmax(a,b) ((a)=(a)>(b)?(a):(b))
#define Cmin(a,b) ((a)=(a)<(b)?(a):(b))
#define D_e(x) printf("&_____%d______&",x);
#define D_e_Line printf("\n-----------------\n");
#define Pause system("pause")
using namespace std;
//const int N=100001;
//const int M=500001;
Ii read(){
int s=,f=;char c;
for(c=getchar();c<''||c>'';c=getchar())if(c=='-')f=-;
while(c>=''&&c<='')s=s*+(c^''),c=getchar();
return s*f;
}
Iv print(int x){
if(x<)putchar('-'),x=-x;
if(x>)print(x/);
putchar(x%^'');
}
int main(){
string s;
while(){
getline(cin,s);
if(s=="E")return ;
int P_o=s.find('O'),P_j=s.find('J'),
c1=P_o,c2=P_j-P_o,c3=s.length()-P_j;
while(){
int flag=;
if(c1)--c1,putchar('Z'),flag=;
if(c2)--c2,putchar('O'),flag=;
if(c3)--c3,putchar('J'),flag=;
if(flag==)break;
}
cout<<endl;
}
}

My.cpp

STD:

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<ctime>
#include<algorithm>
#include<cmath>
//#include<stack>
#define R(a,b,c) for(register int (a)=(b);(a)<=(c);++(a))
#define nR(a,b,c) for(register int (a)=(b);(a)>=(c);--(a))
#define Ii inline int
#define Il inline long long
#define Iv inline void
#define Id inline double
#define Ib inline bool
#define ll long long
#define re register
#define Fill(a,b) memset((a),(b),sizeof((a)))
#define Cmax(a,b) ((a)=(a)>(b)?(a):(b))
#define Cmin(a,b) ((a)=(a)<(b)?(a):(b))
#define D_e(x) printf("&_____%d______&",x);
#define D_e_Line printf("\n-----------------\n");
#define Pause system("pause")
using namespace std;
//const int N=100001;
//const int M=500001;
Ii read(){
int s=,f=;char c;
for(c=getchar();c<''||c>'';c=getchar())if(c=='-')f=-;
while(c>=''&&c<='')s=s*+(c^''),c=getchar();
return s*f;
}
Iv print(int x){
if(x<)putchar('-'),x=-x;
if(x>)print(x/);
putchar(x%^'');
}
int main(){
char s[];
while(scanf("%s",s)!=EOF){
int c1=,c2=,c3=;
if(strcmp(s,"E")==)break;
int len=strlen(s);
R(i,,len-)
c1+=(s[i]=='Z'),
c2+=(s[i]=='O'),
c3+=(s[i]=='J');
while(){
int flag=;
if(c1>)--c1,putchar('Z'),flag=;
if(c2>)--c2,putchar('O'),flag=;
if(c3>)--c3,putchar('J'),flag=;
if(flag==)break;
//D_e(c1);
//D_e_Line;
}
cout<<endl;
}
}
/*
ZOJZOJZOZOZOOOO
ZOJZOJZOZOZOOOO
*/

STD.cpp

RAND:

 #include<bits/stdc++.h>
using namespace std;
#define random(a,b) ((a)+rand()%((b)-(a)+1)) stringstream ss; int main( int argc, char *argv[] )
{
int seed=time(NULL);
if(argc)
{
ss.clear();
ss<<argv[];
ss>>seed;
}
srand(seed);
int T=rand()%+;
while(T--){
int num_z=rand()%+,
num_o=rand()%+,
num_j=rand()%+;
while(num_z--)putchar('Z');
while(num_o--)putchar('O');
while(num_j--)putchar('J');
putchar('\n');
}
putchar('E');
return ;
}

RAND.cpp

05-26 01:20