注册 登录
编程论坛 C++教室

杭电OJ 2000题 题目见正文

Ljldym 发布于 2016-02-28 19:07, 2617 次点击
题目:
只有本站会员才能查看附件,请 登录

提交之后  提示我wrong answer           求助!!!!!!!!!!
程序代码:
#include"iostream"
using namespace std;
void sort(char *_temp, int length);
int main()
{
    char arr[3][3];
    int i;
    for (i = 0; i < 3; i++)
    {
        cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
        sort(arr[i], 3);
    }
    for (i = 0; i < 3; i++)
    {
        cout << arr[i][0] <<" "<< arr[i][1] <<" "<< arr[i][2]<<endl;
    }
}
void sort(char *_temp, int length)
{
    int i, j;
    char cup;
    for (i = 1; i < length;i++)
    for (j = 1; j <= length - i; j++)
    if (_temp[j - 1]>_temp[j])
    {
        cup = _temp[j - 1];
        _temp[j - 1] = _temp[j];
        _temp[j] = cup;
    }
}
2 回复
#2
诸葛欧阳2016-02-28 22:58
你的不满足要求,题目是输入多组而不是三组
#3
rjsp2016-02-29 08:34
程序代码:
#include <iostream>
#include <algorithm> // 从C++11开始,swap移至<utility>文件中

int main( void )
{
    for( char a,b,c; std::cin>>a>>b>>c; )
    {
        if( a > b )
            std::swap( a, b );
        if( a > c )
            std::swap( a, c );
        if( b > c )
            std::swap( b, c );

        std::cout << a << ' ' << b << ' ' << c << '\n';
    }

    return 0;
}
1