你能帮帮小Q吗?
用STL的partition算法直接搞定#include<iostream>#include<algorithm>using namespace std;bool isLower(charc) {returnc>='a';}intmain() {string s;while(cin >> s) {stable_partition(s.begin(),s.end(),isLower);cout << s << endl;}}
import sysimport refor line in sys.stdin:s1 = line.strip()print(re.sub(r'[A-Z]','',s1) + re.sub(r'[a-z]','',s1))
#include<iostream>
#include<string>
using namespace std;
int main()
{string str;
while(cin>>str)
{
int len=str.size();
for(int i=0,count=0;i<len,count<len;i++,count++)
{
if(str[i]>='A'&&str[i]<='Z')
{
char w=str[i];
for(int j=i+1;j<len;j++)
str[j-1]=str[j];
str[len-1]=w;
i=i-1;
}
}
cout<<str<<endl;
}
}
import java.util.Scanner;
/**
* Created by 10648 on 2017/2/22 0022.
*/
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
String string = scanner.nextLine();
char [] chars = string.toCharArray();
int length = string.length();
for (int i = 0; i < length; i ++) {
for (int j = 1; j < length - i; j ++) {
if ((chars[j-1] >= 'A' && chars[j-1] <= 'Z') &&
(chars[j] < 'A' || chars[j] > 'Z')) {
char temp = chars[j-1];
chars[j-1] = chars[j];
chars[j] = temp;
}
}
}
System.out.println(String.valueOf(chars));
}
}
}
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
while (cin >> s) {
int n = s.size();
int p = n;
for (int i = 0;i < p;++i) {
if (s[i] >= 'A' && s[i] <= 'Z') {
char t = s[i];
int j = i;
for (;j < n-1;++j) {
s[j] = s[j + 1];
}
s[j] = t;
--p;
--i;
}
}
cout << s << endl;
}
return 0;
}
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string A;
while(cin>>A)
{
int length = A.size();
for(int i = length-2;i>=0;i--)
{
for(int j = i;(i<length) &&( (A[j]>='A'&&A[j]<='Z') &&
(A[j+1]>='a' && A[j+1]<='z'));j++)
swap(A[j],A[j+1]);
}
cout<<A<<endl;
}
return 0;
}
生生当成倒着的插入排序,只是插入条件改变,前大后小就交换直到尾部。
#include <iostream>
#include <string.h>
using namespace std;
int main(){
string s;
while(cin >> s){
if(s.length() >= 1 && s.length() <= 1000){
for(int i = 0; i < s.length(); i++)
if(s[i] >= 'a' && s[i] <= 'z')
cout << s[i];
for(int i = 0; i < s.length(); i++)
if(s[i] <= 'Z' && s[i] >= 'A')
cout << s[i];
cout << endl;//开始没写这个老是通不过...
}
}
return 0;
}
根据题意输出了正确结果...
这个题仔细看看答案- -把大小写分开输出就可以了。
第一次做对腾讯的题,好鸡冻2333.
类似冒泡排序
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
while (cin >> s) {
int n = s.size();
for (int i = 1; i < n; ++i) {
if (isupper(s[i])) continue; // 大写字母,不进行操作
for (int j = i - 1; j >= 0; --j) { // 小写字母,移动到其之前的所有大写字母之前
if (isupper(s[j])) swap(s[j], s[j + 1]);
}
}
cout << s << endl;
}
return 0;
}
#include <stdio.h>
#include <string.h>
#define MAX_LEN 1000
int main() {
char str[MAX_LEN];
while (gets(str)) {
int len = strlen(str);
for (int i = 0; i < len; ++i) {
if (str[i] >= 97 && str[i] <= 122) {
printf("%c", str[i]);
}
}
for (int i = 0; i < len; ++i) {
if (str[i] >= 65 && str[i] <= 90) {
printf("%c", str[i]);
}
}
printf("\n");
}
return 0;
} import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str;
while((str = br.readLine()) != null) {
for(int i = 0; i < str.length(); i++)
if(str.charAt(i) >= 97 && str.charAt(i) <= 122) System.out.print(str.charAt(i));
for(int i = 0; i < str.length(); i++)
if(str.charAt(i) >= 65 && str.charAt(i) <= 90) System.out.print(str.charAt(i));
System.out.println();
}
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str;
while((str = br.readLine()) != null) {
StringBuilder upper = new StringBuilder();
StringBuilder lower = new StringBuilder();
for(int i = 0; i < str.length(); i++) {
if(str.charAt(i) >= 97 && str.charAt(i) <= 122) lower.append(str.charAt(i));
if(str.charAt(i) >= 65 && str.charAt(i) <= 90) upper.append(str.charAt(i));
}
System.out.println(lower.toString() + upper.toString());
}
}
} public String getResult(String str){
char[] c = str.toCharArray();
int index = 0;
int big = 0;
while (big<c.length&&index<c.length){
if (isSmall(c[index])){ //说明碰到小写字母了
if(big<index){ //说明之前有big出现
if (isSmall(c[big+1])){ //big的下一个是小写字母 那么我们可以直接交换
char temp = c[big];
c[big] = c[index];
c[index] = temp;
big = index;
}else { //big的下一个还是big 如果贸然交换 相对顺序就变了 所以我们要插入排序
char value = c[index];
while (index>big){
c[index] = c[index-1];
index--;
}
c[index] = value;
big = big+1;
}
}else { //这种情况说明之前还没有big出现
big++;
}
}
index++;
}
return String.valueOf(c);
} #include<iostream>
(720)#include<string>
using namespace std;
int main(){
string str;
while(cin>>str){
for(int i=str.size()-1,j=str.size()-1;i>=0;i--){
int flag=isupper(str[i]);
if(flag&&i<j){
for(int k=i;k<j;k++){
swap(str[k],str[k+1]);
}
}
if(flag) j--;
}
cout<<str<<endl;
}
return 0;
} #include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
while(cin>>str)
{
int len = str.length();
for(int i=0; i < len; i++)
{
if(str[i] >= 'A' && str[i] <= 'Z')
{
str += str[i]; // 将大写字母添加到原字符串末尾
str.erase(i, 1); // 删除第i位
i--;
len--;
}
}
cout << str << endl;
}
return 0;
}