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

为什么会错的?有谁帮我看一下吗?谢谢。

Posted by happyface at 2009-01-23 16:09:23 on Problem 1804
/* 
 * File:   POJ-1804-bubble.cpp
 * Author: james
 *
 * Created on 23 January 2009, 15:57
 */

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <iostream>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <string>
#include <complex>
#include <functional>
#include <algorithm>
#include <sstream>
#include <bitset>
#include <fstream>
using namespace std;
int stage[1001];

int main() {
    int n;
    int cas = 1;
    while (scanf("%d", &n) != EOF) {
        while (n--) {
            int t;
            scanf("%d", &t);
            for (int i = 0; i < t; i++)
                scanf("%d", &stage[i]);
            int res = 0;
            for (int i = 0; i < t; i++) {
                for (int j = 0; j < t - i - 1; j++)
                    if (stage[j] > stage[j + 1]) {
                        swap(stage[j], stage[j + 1]);
                        res++;
                    }
            }
            printf("Scenario #%d:\n%d\n\n", cas++, res);
        }
    }
    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