20170811
来源:互联网 发布:有个卖时间的软件 编辑:程序博客网 时间:2024/06/07 06:59
/*设有n个正整数,将他们连接成一排,组成一个最大的多位整数。如:n=3时,3个整数13,312,343,连成的最大整数为34331213。如:n=4时,4个整数7,13,4,246连接成的最大整数为7424613。*///在线编程v1.0//#include <iostream>//#include <vector>//#include <math.h>//#include <stdio.h>////#pragma warning(disable:4996)////using namespace std;////void Swap(int &a, int &b)//{// int temp = a;// a = b;// b = temp;//}////int main()//{// int N;// int TempVarable;//// cin >> N;// vector <int> SaveInputData(N);// vector <int> SaveBitData(N);//// for (int i = 0; i < N; ++i)// {// scanf("%d", &TempVarable);// //SaveInputData.push_back(TempVarable);// SaveInputData[i] = TempVarable;// }//// //判断几位数并且将个位数都存放在一个新的数组// for (int i = 0; i < N; ++i)// {// if (SaveInputData[i] / 10 == 0) //1// SaveBitData[i] = SaveInputData[i];// else if ((SaveInputData[i] / 10 >= 0) && (SaveInputData[i] / 10 < 10)) //2// {// SaveBitData[i] = (SaveInputData[i] / 10);// }//// else if ((SaveInputData[i] / 10 >= 10) && (SaveInputData[i] / 10 < 100)) //3// {// SaveBitData[i] = (SaveInputData[i] / 100);// // }// }// //从大到小排序// for (int i = 0; i < N; ++i)// for (int j = 0; j < N - 1 - i; ++j)// {// if (SaveBitData[j] < SaveBitData[j + 1])// Swap(SaveBitData[j], SaveBitData[j + 1]);///* if (SaveBitData[j] == SaveBitData[j + 1])// {// if (SaveInputData[j] / 10 < SaveInputData[j + 1] / 10)// Swap(SaveBitData[j], SaveBitData[j + 1]);// } */ // }//// //还原成原数// for (int i = 0; i < N; ++i)// {// if (SaveInputData[i] / 10 == 0) //1位数// {// for (int j = 0; j < N; ++j)// {// if (SaveInputData[i] % 10 == SaveBitData[j])// {// SaveBitData[j] = SaveInputData[i];// }// }//// }// else if ((SaveInputData[i] / 10 >= 0) && (SaveInputData[i] / 10 < 10))//2位数// {// for (int j = 0; j < N; ++j)// {// if (SaveInputData[i] / 10 == SaveBitData[j])// {// SaveBitData[j] = SaveInputData[i];// }// }// }//// else if ((SaveInputData[i] / 10 >= 10) && (SaveInputData[i] / 10 < 100))//3位数// {// for (int j = 0; j < N; ++j)// {// if (SaveInputData[i] / 100 == SaveBitData[j])// {// SaveBitData[j] = SaveInputData[i];// }// }// }// }//// //连接成一个数// long long int MaxResult = 0;// int OldCount = 0;// int a = 0;// for (int i = N - 1; i >= 0; i--)// {// int Count = 0;// a = SaveBitData[i];// if (SaveBitData[i] < 10)// {// Count++;// }// while (SaveBitData[i] >= 10)// {// Count++;// SaveBitData[i] = SaveBitData[i] / 10;// }//// OldCount += Count;// // if (i == N-1)// MaxResult = a;// else// {// MaxResult += a * pow(10, OldCount);// }// } // cout << MaxResult;// system("pause");//}////////在线编程v2.0//#include <iostream>//#include <vector>//#include <math.h>//#include <stdio.h>////#pragma warning(disable:4996)////using namespace std;////void Swap(int &a, int &b)//{// int temp = a;// a = b;// b = temp;//}////int main()//{// int N;// int TempVarable;//// cin >> N;// vector <int> SaveInputData(N);// vector <int> SaveBitData(N);//// for (int i = 0; i < N; ++i)// {// scanf("%d", &TempVarable);// //SaveInputData.push_back(TempVarable);// SaveInputData[i] = TempVarable;// }//// //判断几位数并且将个位数都存放在一个新的数组// for (int i = 0; i < N; ++i)// {// if (SaveInputData[i] / 10 == 0) //1// SaveBitData[i] = SaveInputData[i];// else if ((SaveInputData[i] / 10 >= 0) && (SaveInputData[i] / 10 < 10)) //2// {// SaveBitData[i] = (SaveInputData[i] / 10);// }//// else if ((SaveInputData[i] / 10 >= 10) && (SaveInputData[i] / 10 < 100)) //3// {// SaveBitData[i] = (SaveInputData[i] / 100);//// }// }// //从大到小排序// for (int i = 0; i < N; ++i)// for (int j = 0; j < N - 1 - i; ++j)// {// if (SaveBitData[j] < SaveBitData[j + 1]) //首位数字不同排序// {// Swap(SaveBitData[j], SaveBitData[j + 1]);// Swap(SaveInputData[j], SaveInputData[j + 1]);// }// if (SaveBitData[j] == SaveBitData[j + 1]) //首位数字相同// {// if (SaveInputData[j] / 10 < SaveInputData[j + 1] / 10)// {// Swap(SaveInputData[j], SaveInputData[j + 1]);// // }// if (SaveInputData[j] / 10 == SaveInputData[j + 1] / 10)// {// if (SaveInputData[j] < SaveInputData[j + 1])// {// Swap(SaveInputData[j], SaveInputData[j + 1]);// }// }//// } // }//// //还原成原数// for (int i = 0; i < N; ++i)// {// if (SaveInputData[i] / 10 == 0) //1位数// {// for (int j = 0; j < N; ++j)// {// if (SaveInputData[i] % 10 == SaveBitData[j])// {// SaveBitData[j] = SaveInputData[i];// }// }//// }// else if ((SaveInputData[i] / 10 >= 0) && (SaveInputData[i] / 10 < 10))//2位数// {// for (int j = 0; j < N; ++j)// {// if (SaveInputData[i] / 10 == SaveBitData[j])// {// SaveBitData[j] = SaveInputData[i];// }// }// }//// else if ((SaveInputData[i] / 10 >= 10) && (SaveInputData[i] / 10 < 100))//3位数// {// for (int j = 0; j < N; ++j)// {// if (SaveInputData[i] / 100 == SaveBitData[j])// {// SaveBitData[j] = SaveInputData[i];// }// }// }// }//// //连接成一个数// long long int MaxResult = 0;// int OldCount = 0;// int a = 0;// for (int i = N - 1; i >= 0; i--)// {// int Count = 0;// a = SaveBitData[i];// if (SaveBitData[i] < 10)// {// Count++;// }// while (SaveBitData[i] >= 10)// {// Count++;// SaveBitData[i] = SaveBitData[i] / 10;// }//// OldCount += Count;//// if (i == N - 1)// MaxResult = a;// else// {// MaxResult += a * pow(10, OldCount);// }// }// cout << MaxResult;// system("pause");//}//在线编程 sort v3.0//#include <iostream> //#include <string> //#include <vector> //#include <algorithm> //using namespace std; //int CompreFunction( string str1, string str2)//str1>str2 返回1 否则返回 0 //{ // string nstr1 = str1 + str2 ; // string nstr2 = str2 + str1 ; // return nstr1>nstr2; //return (nstr1>nstr2)?1:0;//} //int main() //{ // int Number = 0 ; // cin >> Number;// string tmp ; // vector<string> vstr ; //// for (int i = 0; i < Number; ++i)// { // cin>>tmp ; // vstr.push_back(tmp); // } // sort(vstr.begin(), vstr.end(), CompreFunction);// for (auto c : vstr) // cout << c; /* for (int i = 0; i < Number; ++i)// cout << vstr[i]; */ // cout<<endl; // return 0; //}//lambda函数#include <string>#include <algorithm>#include <vector>#include <iostream>using namespace std;int main() { int n; cin >> n; vector<string> sArray; for (int i = 0; i<n; i++) { string temp; cin >> temp; sArray.push_back(temp); } sort(sArray.begin(), sArray.end(), [](string s1, string s2){ return (s1 + s2) >(s2 + s1); }); for (auto s : sArray) { cout << s; } return 0;}
阅读全文
0 0
- 20170811
- 20170811
- 20170811
- 20170807~20170811
- Redis笔记20170811视频
- 20170811 servlet 零散小结2
- 20170811(回朔法复习 二分法复习)
- MySQL学习笔记——20170811
- OpenCV之视频文件编解码 ---20170811
- 公众号“今日作文素材”文章列表 (20170805-20170811)
- 20170811工作记账流水(2017-08-11 10:00)
- Java 的发展历史, 现状与未来(完整总结, 20170811 更新)
- 约瑟环解法
- spring IOC和DI
- 31. Next Permutation
- HDOJ1176 免费馅饼 简单的二维DP
- celery+Rabbit MQ的安装和使用
- 20170811
- 洛谷3379(LCA模板优化)
- 单行注释、多行注释、文档注释最完美的解释、导出API
- Java_23种设计模式(一)
- 笔记本无缘无故自动唤醒是怎么回事?
- 虚拟机CentOS7安装python3.6.2及requests模块的问题汇总
- Android中MediaCodec的使用
- 51nod-1434 区间LCM
- docker在windows 7上连接终端(ssh)