zoukankan      html  css  js  c++  java
  • 字符串内排序【简单题】

    题目描述:

    输入一个字符串,长度小于等于200,然后将输出按字符顺序升序排序后的字符串。

    输入:

    测试数据有多组,输入字符串。

    输出:

    对于每组输入,输出处理后的结果。

    样例输入:
    bacd
    样例输出:
    abcd
     1 #include <iostream>
     2 #include <string>
     3 
     4 using namespace std;
     5 
     6 int main(){
     7     int i, j;
     8     string s;
     9     char temp;
    10     while(cin>>s){
    11         for(i = 0; i < s.length()-1; i++){
    12             for(j = 0; j < s.length()-1-i; j++){
    13                 if(s[j] > s[j+1]){
    14                     temp = s[j];
    15                     s[j] = s[j+1];
    16                     s[j+1] = temp;
    17                 }
    18             }
    19         }
    20         cout << s << endl;
    21     }
    22     return 0;
    23 }

    这道题其实是很水的,不过向来有些畏惧字符串的问题,此题还是用的冒泡,快排我实在不会了。。。

    刚开始想用C,发现对于字符串的处理,还是C++比较给力啊!!!

    Everything will be ok in the end. If it is not ok then it is not the end.
  • 相关阅读:
    扫描线
    Assign the task HDU
    Can you answer these queries? HDU
    Tunnel Warfare HDU
    Mayor's posters POJ
    not friendly,
    招财铃:即时通信 openfire ,
    不再是可怕的汇编,
    转:宏指令,
    build path,
  • 原文地址:https://www.cnblogs.com/shirleytian/p/3325203.html
Copyright © 2011-2022 走看看