#include <iostream>
#include <string>
using namespace std;
string str[200];
int main()
{
int m;
int i, j;
string _str;
int min;//记录排序最小的位置
cin >> m;
for (i = 0; i < m; i++) {
cin >> str[i] ;
}
//类似比较数字大小进行字符串大小比较并交换顺序for (i = 0; i < m; i++) {
_str = str[i];
min = i;
for (j = i; j < m; j++) {
//判断最小组合数if ((_str + str[j])>(str[j] + _str)) {
_str = str[j];
min = j;
}
}
//交换位置str[min] = str[i];
str[i] = _str;
}
for (i = 0; i < m; i++) {
cout << str[i];
}
cout << endl;
return0;
}
/*
*****判断最小组合数*****
if (_str > str[j]) {
_str = str[j];
min = j;
}
******错误做法原因******
例如当1和100比较时会输出1100而非1001
*/
2、矩阵坐标变换
特殊角度
代码如下
#include<iostream> usingnamespacestd;
int main() {
int n;
int i, j;
int x1 = 0, x2 = 0, x3 = 0;
cin >> n;
cout << endl << "初始坐标:" << endl;
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
cout << "(" << i << "," << j << ") ";
}
cout << endl;
}
cout << endl;
cout << "顺时针转90°:" << endl;
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
cout << "(" << n - j + 1 << "," << i << ") ";
}
cout << endl;
}
cout << endl;
cout << "逆时针转90°:" << endl;
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
cout << "(" << j << "," << n - i + 1 << ") ";
}
cout << endl;
}
cout << endl;
cout << "顺/逆时针转180°:" << endl;
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
cout << "(" << n - i + 1 << "," << n - j + 1 << ") ";
}
cout << endl;
}
cout << endl;
cout << "水平翻转:" << endl;
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
cout << "(" << i << "," << n - j + 1 << ") ";
}
cout << endl;
}
cout << endl;
return0;
}