#include <iostream> #include <string> using namespace std; int main() { string s; while(cin>>s && s != "E") { int cnt[3] = {0}; string t = "ZOJ"; for(auto e : s) { cnt[t.find(e)]++; } while(cnt[0] > 0 || cnt[1] > 0 || cnt[2] > 0) { for(int i = 0; i<3; i++) { if(cnt[i] > 0) { cout<<t[i]; cnt[i]--; } } } cout<<endl; } }
#include<iostream> #include<algorithm> using namespace std; int main() { string s; cin >> s; int turn = 0; while(!s.empty()) { if(turn==0) { string::iterator it = find(s.begin(), s.end(), 'Z'); if (it != s.end()) { cout << 'Z'; s.erase(it); } } if(turn==1) { string::iterator it = find(s.begin(), s.end(), 'O'); if (it != s.end()) { cout << 'O'; s.erase(it); } } if(turn==2) { string::iterator it = find(s.begin(), s.end(), 'J'); if (it != s.end()) { cout << 'J'; s.erase(it); } } turn = (turn+1) % 3; } return 0; }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); char[] array = scanner.nextLine().toCharArray(); int z=0; int o=0; int j= 0; for (char c : array) { switch (c) { case 'Z': z++;break; case 'O': o++;break; case 'J': j++;break; } } StringBuilder builder = new StringBuilder(); while (z>0||o>0||j>0){ if (z>0) { builder.append("Z"); z--; } if (o>0) { builder.append("O"); o--; } if (j>0) { builder.append("J"); j--; } } System.out.println(builder.toString()); } }
//果然写的很麻烦,一起判断的话会好很多 #include<iostream> #include<cstring> using namespace std; int main(){ char ch[101]; while(cin>>ch){ int a=0,b=0,c=0; for(int i=0;i<strlen(ch);i++){ if(ch[i]=='Z') a++; else if(ch[i]=='O') b++; else if(ch[i]=='J') c++; } if(a>=b&&b>=c){ for(int i=0;i<c;i++) cout<<"ZOJ"; for(int i=0;i<b-c;i++) cout<<"ZO"; for(int i=0;i<a-b;i++) cout<<"Z"; } else if(a>=c&&c>=b){ for(int i=0;i<b;i++) cout<<"ZOJ"; for(int i=0;i<c-b;i++) cout<<"ZJ"; for(int i=0;i<a-c;i++) cout<<"Z"; } else if(b>=c&&c>=a){ for(int i=0;i<a;i++) cout<<"ZOJ"; for(int i=0;i<c-a;i++) cout<<"OJ"; for(int i=0;i<b-c;i++) cout<<"O"; } else if(b>=a&&a>=c){ for(int i=0;i<c;i++) cout<<"ZOJ"; for(int i=0;i<a-c;i++) cout<<"ZO"; for(int i=0;i<b-a;i++) cout<<"O"; } else if(c>=a&&a>=b){ for(int i=0;i<b;i++) cout<<"ZOJ"; for(int i=0;i<a-b;i++) cout<<"ZJ"; for(int i=0;i<c-a;i++) cout<<"J"; } else if(c>=b&&b>=a){ for(int i=0;i<a;i++) cout<<"ZOJ"; for(int i=0;i<b-a;i++) cout<<"OJ"; for(int i=0;i<c-b;i++) cout<<"J"; } } }
try: while True: string = input() numZ = string.count('Z') numO = string.count('O') numJ = string.count('J') result = "" for i in range(max(numZ,numO,numJ)): if numZ: #如果该数字不为0 result += "Z" numZ -= 1 if numO: result += "O" numO -= 1 if numJ: result += "J" numJ -= 1 print(result) except Exception: pass
package NiuKeBianMa;
import java.util.Scanner;
//一步一步来就好了
public class Main104 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
String string = scanner.nextLine();
if (string.equals("E")) {
break;
}
// char[] cs = {,'O','J'};
int[] arr = new int[3];
for (int i = 0; i < string.length(); i++) {
if (string.charAt(i) == 'Z') {
arr[0]++;
}
if (string.charAt(i) == 'O') {
arr[1]++;
}
if (string.charAt(i) == 'J') {
arr[2]++;
}
}
StringBuffer stringBuffer = new StringBuffer();
while (arr[0] > 0 || arr[1] > 0 || arr[2] > 0) {
if (arr[0] > 0) {
stringBuffer.append("Z");
}
if (arr[1] > 0) {
stringBuffer.append("O");
}
if (arr[2] > 0) {
stringBuffer.append("J");
}
arr[0]--;
arr[1]--;
arr[2]--;
}
System.out.println(stringBuffer.toString());
}
}
}
#include<stdio.h> int main() { char s[100]; gets(s); int a=0,b=0,c=0,n; for(int i=0;s[i]!='\0';i++) { if(s[i]=='Z') a++; else if(s[i]=='O') b++; else if(s[i]=='J') c++; n=i+1; } for(int i=0;i<n;i++) { if(a!=0) { printf("Z"); a--; } if(b!=0) { printf("O"); b--; } if(c!=0) { printf("J"); c--; } } }
#include<iostream> #include<stdio.h> #include<cstring> #include<map> using namespace std; int main(){ string s; while(cin>>s){ map<char,int> m; m['Z']=m['O']=m['J']=0; for(int i=0;i<s.length();i++){ m[s[i]]++; } while(m['Z']>0||m['O']>0||m['J']>0){ if(m['Z']>0) {cout<<'Z';m['Z']--;} if(m['O']>0) {cout<<'O';m['O']--;} if(m['J']>0) {cout<<'J';m['J']--;} } cout<<endl; } return 0; }
#include<stdio.h> int main() { char a[100]; gets(a); int i,z=0,o=0,j=0; for(i=0;a[i]!='\0';i++) //1.记录zoj的个数 { if(a[i]=='Z') z++; if(a[i]=='O') o++; if(a[i]=='J') j++; } while(z+o+j!=0)//2.按顺序输出 { if(z!=0) { printf("Z");z--; } if(o!=0) { printf("O");o--; } if(j!=0) { printf("J");j--; } } }
#include <iostream> using namespace std; int main() { string str_str; while (cin>>str_str) { int cnt_z = 0, cnt_o = 0, cnt_j = 0; for (int i = 0; i < str_str.size(); ++i) { if ('Z' == str_str[i]) ++cnt_z; else if ('O' == str_str[i]) ++cnt_o; else if ('J' == str_str[i]) ++cnt_j; } while (cnt_z > 0 || cnt_o > 0 || cnt_j > 0) { if (cnt_z > 0) { cout << 'Z'; --cnt_z; } if (cnt_o > 0) { cout << 'O'; --cnt_o; } if (cnt_j > 0) { cout << 'J'; --cnt_j; } } cout << endl; } return 0; }
#include <stdio.h> #include <string.h> #define N 101 int main() { char str[N]; while(gets(str)) { int z=0, o=0, j=0; int len=strlen(str); for(int i=0; i<len; i++) { if(str[i]=='Z') z++; if(str[i]=='O') o++; if(str[i]=='J') j++; } while(z+o+j>0) { if(z>0) { printf("Z"); z--; } if(o>0) { printf("O"); o--; } if(j>0) { printf("J"); j--; } } printf("\n"); } return 0; }
#include <iostream> #include<string> using namespace std; int main() { string s; cin>>s; while(s.size()){ if(s.find('Z')<s.size()){ cout<<'Z'; s.erase(s.find('Z'), 1); } if(s.find('O')<s.size()){ cout<<'O'; s.erase(s.find('O'), 1); } if(s.find('J')<s.size()){ cout<<'J'; s.erase(s.find('J'), 1); } } }
#include <bits/stdc++.h> using namespace std; int main() { string s; getline(cin, s); int z=count(s.begin(),s.end(),'Z'); int o=count(s.begin(),s.end(),'O'); int j=s.size()-z-o; while (z>0||o>0||j>0){ if(z>0){ cout<<"Z"; z--; } if(o>0){ cout<<"O"; o--; } if(j>0){ cout<<"J"; j--; } } cout<<endl; } // 64 位输出请用 printf("%lld")
#include <iostream> #include <map> #include <string> using namespace std; int main(){ string str; while(cin >> str){ map<char, int> mymap = {{'Z', 0}, {'O', 0}, {'J', 0},}; for(int i=0; i<str.size(); ++i){ mymap[str[i]]++; } for(int m,i=0; i<mymap['Z'] || i< mymap['O'] || i< mymap['J']; ++i){ if(i<mymap['Z']) cout << 'Z'; if(i<mymap['O']) cout << 'O'; if(i<mymap['J']) cout << 'J'; } cout << endl; } }
#include <iostream> #include <string> using namespace std; int main() { string str; while (cin >> str) { int z = 0, o = 0, j = 0; //统计ZOJ三个字符的个数 for (const auto& ch : str) { switch (ch) { case 'Z': z++; break; case 'O': o++; break; case 'J': j++; } } while (z || o || j) { if (z) { cout << 'Z'; z--; } if (o) { cout << 'O'; o--; } if (j) { cout << 'J'; j--; } } } return 0; }
#include <iostream> using namespace std; int main(){ int timesZ = 0 ,timesO = 0, timesJ = 0; char str[101]; while(cin >> str){ for(int i = 0 ; str[i] != '\0' ; i++){ if(str[i] == 'Z') timesZ++; else if(str[i] == 'O') timesO++; else timesJ++; } while(timesZ || timesO || timesJ){ if(timesZ){ cout << "Z"; timesZ--; } if(timesO){ cout << "O"; timesO--; } if(timesJ){ cout << "J"; timesJ--; } } } return 0; }
#include <iostream> #include <string> using namespace std; int main() { string str; int z,o,j; while(cin>>str) { z=0;j=0;o=0; while(z!=str.size()||o!=str.size()||j!=str.size()) { while(str[z]!='Z'&&z!=str.size()) z++; if(z<str.size()) cout<<str[z++]; while(str[o]!='O'&&o!=str.size()) o++; if(o<str.size()) cout<<str[o++]; while(str[j]!='J'&&j!=str.size()) j++; if(j<str.size()) cout<<str[j++]; } cout<<endl; } }
#include<iostream> #include<string> using namespace std; int main(){ string s; while(getline(cin,s)){ int z=0,o=0,j=0; for(int i=0;i<s.size();i++){ if(s[i]=='Z') z++; else if(s[i]=='O') o++; else if(s[i]=='J') j++; } for(int k=0;k<s.size();k++){ if(z){ printf("Z"); z--; } if(o){ printf("O"); o--; } if(j){ printf("J"); j--; } } printf("\n"); } }