完美的代价
#include<iostream>
#include<string>
using namespace std;
int main(){
int N;
string s;
cin>>N>>s;
int f=N-1;
int step=0;
bool flag=false;
for(int i=0;i<f;i++)
{
for(int j=f;j>=i;j--)
{
if(i==j)
{
if(N%2==0||flag==5
mamadtrue)
{
cout<<"Impossible";
return 0;
}
flag=true;
step+=N/2-i;
}
else if (s[i]==s[j])
{
for(int k=j;k<f;k++)
{
swap(s[k],s[k+1]);
step++;
}
f--;
break;
}
}
}
cout<<step;
return 0;
}
数的读法
#include<iostream>
using namespace std;
int main(){
char *num[]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
char *wei[]={"shi","bai","qian","wan","yi"};
char *str[20];
int i,j,k,n,l[2]={0};
i=0;j=0;
cin>>n;
while(n>0){
k=n%10;
n/=10;
if(k>0){
if(i>0){
if(i>=4 && !l[i/4-1]){
l[i/4-1]=1;
str[j++]=wei[i/4+2];
}
if(i%4!=0){
str[j++]=wei[i%4-1];
}
}
str[j++]=num[k];
}
else if(j>0 && str[j-1]!=num[0]){
str[j++]=num[0];
}
i++;
}
if(!(str[j-1]=="yi" && j>1 && str[j-2]=="shi"))
cout<<str[j-1]<<" ";
for(i=j-2;i>=0;i--){
cout<<str[i]<<" ";
}
return 0;
}