Ver código fonte

字符串的排序

Solitude 5 anos atrás
pai
commit
5810ea41b8
1 arquivos alterados com 24 adições e 0 exclusões
  1. 24 0
      F.cpp

+ 24 - 0
F.cpp

@@ -0,0 +1,24 @@
+#include<bits/stdc++.h>
+using namespace std;
+bool cmp(string a,string b)
+{
+    if(a.length()==b.length())
+        return a<b;
+    else
+        return a.length()<b.length();
+}
+int main()
+{
+    int n;
+    while(cin>>n)
+    {
+        string str[n];
+        int i =n;
+        while(i)
+            cin>>str[--i];
+        sort(str,str+n,cmp);
+        for(i=0;i<n;i++)
+            cout<<str[i]<<endl;
+    }
+    return 0;
+}