A. ABC String
https://codeforces.com/contest/1494/problem/A
选择排序
for(int i=0; i<n-1; i++)
{
index=i;
for(int j=i+1; j<n; j++)
if(a[j]>a[index]) index=j;
if(index!=0)
{
max=a[i];
a[i]=a[index];
a[index]=max;
}
冒泡排序
for(int pass=1;pass<size;pass++)//size,无序数个数
{
for(int i=0; i<size-pass; i++)
if(a[i]>a[i+1]) {
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
最大公约数
using namespace std;
//辗转相除法
int gcd1(int a,int b)
{
int temp;
if(a0||b0)
return 0;
if(a<b)
{ temp=a;a=b;b=temp;} //求最小值最大值,大的用a表示,小的用b表示
while(b!=0) //用循环求最大公约数
{
temp=a%b;
a=b;
b=temp;
}
return a; //返回最大公约数
}
//枚举法
int gcd2(int a,int b)
{
int temp;
temp=(a>b)?b:a; //求两数中的最小数
while(temp>0) //最小数自减,直到可以同时被a,b整除
{
if (a%temp0&&b%temp0)
break;
temp–;
}
return temp; //返回最大公约数
}