输入十个国家的名字(英文),按照从大到小的顺序输出。求程序设计

2025-01-06 16:55:21
推荐回答(5个)
回答1:

这个学了忘得快

回答2:

#include "stdio.h"

#include "string.h"

int main()

{

      char str[10][30]={0};

      int i,j;

      char tmp[30]={0};

      printf("请输入10个国家的名字(英文):\n");

      for(i=0;i<10;i++)

          gets(str[i]);

      //排序:

      for(i=0;i<9;i++)

           for(j=i+1;j<10;j++)

            if(strcmp(str[i],str[j])>0)

            {

                 memset(tmp,0,30);

                 strncpy(tmp,str[i],strlen(str[i]));

                 memset(str[i],0,30);

                 strncpy(str[i],str[j],strlen(str[j]));

                 memset(str[j],0,30);

                 strncpy(str[j],tmp,strlen(tmp));

           }

         //输出

        printf("从小到大输出:\n");

        for(i=0;i<10;i++)

            puts(str[i]);

     

 

 

 

}

回答3:

#include
using std::cout;
using std::cin;
using std::endl;
#include
#define MAX 10
int main()
{
    char countries[MAX][20] ={0};
    char *ordered[MAX];
    char *temp;
    int i, j;
                                                                     
    for (i=0; i    {
                                                                         
        cout << "Input country ("<< i+1 <<"):";
        cin >> countries[i];
        ordered[i] = countries[i];
                                                                         
        for (j=i; j>0; j--)
        {
            if(strcmp(ordered[j],ordered[j-1])>0)
            {
                temp = ordered[j-1];
                ordered[j-1] = ordered[j];
                ordered[j] = temp;
            }
        }
    }
                                                                     
    for (i=0; i        cout<    return 0;
}

你没说要什么语言, 这是C++的

回答4:

#include
#include
void main()
{
char str[5],str1[5],*p1,*p2;
int i;
printf("请输入国家名字:\n");

for(i=0;i<5;i++)
scanf("%s",&str[i]);

for(p1=str,p2=str1;p1!='\0',p2!='\0';p1++,p2++)
if(strcmp(p1,p2)>0)
{
strcpy(p1,p2);

}

for(i=0;i<5;i++)
printf("%s",str);
}

回答5:

Russia俄罗斯1,707.5
加拿大 997.1
Chinese 中国960.1 4
United States美国936.4
Brazil巴西854.7
Australia澳大利亚774.1
India印度328.8
Argentina阿根廷278.0
kazakhstan哈萨克斯坦 271.7
Sudan苏丹250.6