2 qq 32554019 qq_32554019 于 2016.03.31 11:04 提问

我在oj上输出时提示格式错误,求大神指教
c++

#include using namespace std; int main() { int n; cin >> n; int * p = new int[n * 2]; int i; for (i = 0; i < n; i++) { cin >> p[i * 2]; cin >> p[i * 2 + 1]; } for (i = 0; i < n; i++) { int a = p[i * 2]; int b = p[i * 2 + 1]; if (a > b || a <= 0 || b >= 10) { cout << "Input Error!"; continue; } for (int j = a; j <= b; j++) { for (int k = 1; k <=j; k++) { cout << j << "*" << k << "=" << j * k << "\t"; } cout << endl; } if (i != n - 1) cout << endl; } return 0; }

3个回答

qq423399099
qq423399099   Ds   Rxr 2016.03.31 11:25

楼主试试这种,OJ上有些会把输入输出写一起,可能真正的意思是输入一组数输出一组数,可能会AC

 #include<iostream>
using namespace std;
int main() { 
    int n; 
    cin >> n; 
    int * p = new int[n * 2]; 
    int i; 
    /*
    for (i = 0; i < n; i++) { 
        cin >> p[i * 2]; 
        cin >> p[i * 2 + 1]; 
    } */
    for (i = 0; i < n; i++) { 
        //int a = p[i * 2]; 
        //int b = p[i * 2 + 1]; 
        int a, b;
        cin >> a >> b;
        if (a > b || a <= 0 || b >= 10) { 
            cout << "Input Error!"; 
            continue;
        } 
        for (int j = a; j <= b; j++) { 
            for (int k = 1; k <=j; k++) { 
                cout << j << "*" << k << "=" << j * k << "\t"; 
            } 
            cout << endl; 
        } 
        if (i != n - 1) 
            cout << endl; 
    } 
    return 0; 
}
flx413
flx413   2016.03.31 23:50

看看是不是因为行末多了空格?

huatian5
huatian5   2016.04.03 11:58

应该是题目隐含了格式控制,你要看清题目要求,不然会wa很多次的!!

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!