Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪位同学能帮忙看一下c++代码,我们只学到了数组还有循环,所以比较麻烦

Posted by 3018001058 at 2019-12-14 14:00:59 on Problem 1007
#include<iostream>
using namespace std;

int main()
{
    char litter[100][50] = {};
    int n = 0,m = 0;
    int temp[50] = {0};
    cin>>n>>m;

    for(int k=0;k<m;k++)
    {
        for(int l=0;l<n;l++)
        {
            cin>>litter[k][l];
        }
    }

    for(int p=0;p<m;p++)
    {
       for(int k=0;k<n;k++)
        {
            for(int l=k+1;l<n;l++)
            {
                while(litter[p][k]>litter[p][l])
                {
                    temp[p]++;
                    break;
                }
            }
        }
    }

    int number[50] = {0};

    for(int k=0;k<m;k++)
    {
        number[k] = temp[k];
    }

    int t = 0;
    for(int k=0;k<m;k++)
    {
        for(int l=k+1;l<m;l++)
        {
            if(temp[k]>temp[l])
            {
                t = temp[l];
                temp[l] = temp[k];
                temp[k] = t;
            }
        }
    }

    for(int k=0;k<m;k++)
    {
        for(int l=0;l<m;l++)
        {
            if(temp[k]==number[l])
            {
                for(int p=0;p<n;p++)
                {
                    cout<<litter[l][p];
                }
                cout<<endl;
            }
        }
    }

    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator