http://ac.jobdu.com/problem.php?pid=1032
2012-10-22 16:17
337 查看
题目描述:
读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当某个字符用完时,剩下的仍然按照ZOJ的顺序输出。
输入:
题目包含多组用例,每组用例占一行,包含ZOJ三个字符,当输入“E”时表示输入结束。
1<=length<=100。
输出:
对于每组输入,请输出一行,表示按照要求处理后的字符串。
具体可见样例。
样例输入:
样例输出:
[cpp] view
plaincopy
#include <iostream>
#include <string>
#include <algorithm>
#include <memory.h>
#include <cstdio>
#include <cstdlib>
using namespace std;
int a[3];
char b[3] = {'Z', 'O', 'J'};
int main(){
//freopen("in.txt", "r", stdin);
string s;
while(cin>>s, s!="E"){
int len = s.length();
for(int i=0;i<3;++i)
a[i] = 0;
for(int i=0;i<len;++i){
switch(s[i]){
case 'Z':a[0]++;break;
case 'O':a[1]++;break;
case 'J':a[2]++;break;
}
}
for(int i=0;len;i=(i+1)%3){
if(a[i]!=0){
len--;
a[i]--;
printf("%c", b[i]);
}
}
printf("\n");
}
//fclose(stdin);
}
读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当某个字符用完时,剩下的仍然按照ZOJ的顺序输出。
输入:
题目包含多组用例,每组用例占一行,包含ZOJ三个字符,当输入“E”时表示输入结束。
1<=length<=100。
输出:
对于每组输入,请输出一行,表示按照要求处理后的字符串。
具体可见样例。
样例输入:
ZZOOOJJJ ZZZZOOOOOJJJ ZOOOJJ E
样例输出:
ZOJZOJOJ ZOJZOJZOJZOO ZOJOJO
[cpp] view
plaincopy
#include <iostream>
#include <string>
#include <algorithm>
#include <memory.h>
#include <cstdio>
#include <cstdlib>
using namespace std;
int a[3];
char b[3] = {'Z', 'O', 'J'};
int main(){
//freopen("in.txt", "r", stdin);
string s;
while(cin>>s, s!="E"){
int len = s.length();
for(int i=0;i<3;++i)
a[i] = 0;
for(int i=0;i<len;++i){
switch(s[i]){
case 'Z':a[0]++;break;
case 'O':a[1]++;break;
case 'J':a[2]++;break;
}
}
for(int i=0;len;i=(i+1)%3){
if(a[i]!=0){
len--;
a[i]--;
printf("%c", b[i]);
}
}
printf("\n");
}
//fclose(stdin);
}
相关文章推荐
- http://ac.jobdu.com/problem.php?pid=1030
- http://ac.jobdu.com/problem.php?pid=1024
- http://ac.jobdu.com/problem.php?pid=1027
- http://ac.jobdu.com/problem.php?pid=1022
- http://ac.jobdu.com/problem.php?pid=1020
- http://ac.jobdu.com/problem.php?pid=1025
- http://ac.jobdu.com/problem.php?pid=1021
- http://ac.jobdu.com/problem.php?pid=1026
- http://ac.jobdu.com/problem.php?pid=1017
- http://ac.jobdu.com/problem.php?pid=1008
- http://ac.jobdu.com/problem.php?pid=1019
- http://ac.jobdu.com/problem.php?pid=1014
- http://ac.jobdu.com/problem.php?pid=1009
- 二分查找 http://ac.jobdu.com/problem.php?pid=1545
- http://ac.jobdu.com/problem.php?pid=1033
- http://ac.jobdu.com/problem.php?pid=1012
- http://ac.jobdu.com/problem.php?pid=1007
- http://ac.jobdu.com/problem.php?pid=1013
- http://ac.jobdu.com/problem.php?pid=1006
- http://ac.jobdu.com/problem.php?pid=1010