悬赏一贯

UVA10048 Audiophobia

Tjaweiof @ 2023-08-08 19:37:45

#include <bits/stdc++.h>
using namespace std;
int c, s, q, u, v, w, tot = 0;
long long d[101][101];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while (1){
        cin >> c >> s >> q;
        if (c == 0 && s == c && q == 0){
            break;
        } else {
            if (tot){
                cout << endl << endl;
            }
            cout << "Case #" << ++tot << endl;
        }
        for (int i = 1; i <= c; i++){
            for (int j = 1; j <= c; j++){
                d[i][j] = 0x3f3f3f3f;
            }
        }
        for (int i = 1; i <= c; i++){
            d[i][i] = 0;
        }
        while (s--){
            cin >> u >> v >> w;
            d[u][v] = w;
            d[v][u] = w;
        }
        for (int k = 1; k <= c; k++){
            for (int i = 1; i <= c; i++){
                for (int j = 1; j <= c; j++){
                    d[i][j] = min(d[i][j], max(d[i][k], d[k][j]));
                }
            }
        }
        while (q--){
            cin >> u >> v;
            if (d[u][v] == 0x3f3f3f3f){
                cout << "no path";
            } else {
                cout << d[u][v];
            }
            if (q){
                cout << endl;
            }
        }
    }
    return 0;
}

九九海子把


by LeoZhao2023 @ 2023-08-08 19:51:04

你这个程序两个Case之间有两行。因为你最后q到0时已经退出了循环,所以最后会换行,再加上上面的两个换行,一共换了3次行,隔了两行。


by Tjaweiof @ 2023-08-08 20:54:32

@LeoZhao2023 我试的时候没问题啊?


by Tjaweiof @ 2023-08-09 13:37:42

@LeoZhao2023 当q = 1的时候没退出,后面再--,跟--q是不一样的


by Tjaweiof @ 2023-08-09 13:40:28

已经AC了,输出的最后少了个换行


|