PDA

View Full Version : آموزش: برنامه ای که نام شهر ها را بر اساس کد اسکی مرتب سازی می کند .



sourcecode
سه شنبه 01 مهر 1393, 11:22 صبح
#include "stdafx.h"
#include <iostream>
#include <cstring>
//or
//#include <string.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char a[6][10]={
"London",
"Milan",
"Hamburg",
"Barcelona",
"Arak",
"New York"
};
char temp[10];
int i,j,m=0,z=0,x=0;
for(i=1;i<6;i++)
for(j=0;j<6-i;j++)
{
if( strcmp(a[j],a[j+1]) > 0 )
{
strcpy_s(temp,a[j]);
strcpy_s(a[j],a[j+1]);
strcpy_s(a[j+1],temp);
}
}
for(int i=0;i<6;i++)
cout<<a[i]<<endl;
cout<<endl;
system("pause");
return 0;
}