Description:
将01串首先按长度排序,长度相同时,按1的个数多少进行排序,1的个数相同时再按ASCII码值排序。
Input:
输入数据中含有一些01串,01串的长度不大于256个字符。
Output:
重新排列01串的顺序。使得串按基本描述的方式排序。
Sample Input:
10011111
00001101
1010101
1
0
1100
Sample Output:
0
1
1100
1010101
00001101
10011111
只是用for循环,问题在str[n].size()长度的读取不准
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{
string str[100];
int i = 0, a[257] = {
0 };
while (cin >> str[i++]);//最终一共有i串,最后一个串应该是i-1个
//长度
for (int n = 0; n < i-1; n++)//输入ctrl+z作为结束的时候,有可能进行了i++;
{
int min= n;
a[str[n].size()]++;//记录每个串的长度
cout << str[n].size() << endl;
for (int m = n + 1; m < i; m++)
{
if (str[m].size() < str[min].size())min