竹園論壇

標題: TOJ 170 [打印本頁]

作者: jill880829    時間: 2014-11-23 00:41
標題: TOJ 170
本帖最後由 domen111 於 2014-11-23 11:51 編輯

[C++] 純文本查看 復制代碼

#include<iostream>
using namespace std;
void f(int a)
{
        for(int i=0;i<a;i++)
        {
                for(int j=a-i-1;j>0;j--) cout<<' ';
                for(int k=0;k<2*i+1;k++) cout<<'*';
                cout<<endl;
        }
}
void g(int a)
{
        for(int i=0;i<a;i++)
        {
                for(int j=0;j<i+1;j++)
                {
                        for(int k=a-j-1;k>0;k--) cout<<' ';
                        for(int l=0;l<2*j+1;l++) cout<<'*';
                        cout<<endl;
                }
        }
}
void h(int a)
{
        for(int m=0;m<a;m++)
        {
                for(int n=a+1-m;n>0;n--) cout<<' ';
                for(int o=0;o<2*m+1;o++) cout<<'*';
                cout<<endl;
        }
        for(int p=0;p<2*(a+2)-1;p++) cout<<'#';
        cout<<endl;
}
int main()
{
        int a,c[30];
        char b[30];
        while(cin>>a)
        {
                for(int i=0;i<a;i++)
                {
                        char b1;
                        int c1;
                        cin>>b1>>c1;
                        b=b1;
                        c=c1;
                }
                for(int j=0;j<a;j++)
                {
                        if(b[j]=='A')
                        {
                                f(c[j]);
                                cout<<endl;
                        }
                        else if(b[j]=='B')
                        {
                                for(int q=0;q<2;q++)
                                {
                                        f(c[j]);
                                }
                                cout<<endl;
                        }
                        else if(b[j]=='C')
                        {
                                g(c[j]);
                                cout<<endl;
                        }
                        else if(b[j]=='D')
                        {
                                f(10*c[j]);
                                cout<<endl;
                        }
                        else if(b[j]=='E')
                        {
                                h(c[j]);
                                cout<<endl;
                        }
                        else if(b[j]=='F')
                        {
                                f(2*c[j]);
                                cout<<endl;
                        }
                        else if(b[j]=='G')
                        {
                                f(3*c[j]);
                                cout<<endl;
                        }
                        else if(b[j]=='H')
                        {
                                f(7*c[j]);
                                cout<<endl;
                        }
                        else if(b[j]=='I')
                        {
                                f(4*c[j]-1);
                                cout<<endl;
                        }
                }
                cout<<endl;
        }
        return 0;
}


我測試TOJ 170的範例輸入輸出結果都是對的,但上傳是WA,請求幫忙



請加上程式碼標籤,使用說明請參考這篇

作者: domen111    時間: 2014-11-23 12:13
本帖最後由 domen111 於 2014-11-23 12:17 編輯

第100行的換行刪掉就ok了

我的輸入說明前兩行寫錯了,這樣看起來好奇怪

多筆測資。
每一筆測資首先有一個整數T,代表一共幾筆測資。


應該是:

多筆測資,第一行有一個整數T,代表一共幾筆測資。






歡迎光臨 竹園論壇 (http://forum.tfcis.org/) Powered by Discuz! X3.2