C++编写程序对12个月的英文单词根据字典序进行从小到大的排序,请使用string不使用向量!
1个回答
展开全部
//#include "stdafx.h"//vc++6.0加上这一行.
#include <iostream>
#include <string>
using namespace std;
int main(void){
string m[12]={"January","February","March","April","May","June",
"July","August","September","October","November","December"},tmp;
for(int i=0;i<12;i++){
for(int k=i,j=k+1;j<12;j++)
if(m[k]>m[j]) k=j;
if(k!=i){
tmp=m[i];
m[i]=m[k];
m[k]=tmp;
}
}
for(i=0;i<12;cout << m[i++] << ' ');
cout << endl;
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询