#1089: 輸出了額外的第八行"no"...


a310623195623 (.)

學校 : 臺北市立成功高級中學
編號 : 3215
來源 : [140.113.247.113]
最後登入時間 :
2014-03-10 19:28:18
a016. 數獨(SUDOKU) | From: [61.31.140.139] | 發表日期 : 2008-12-20 10:41

不知道為什麼會這樣耶@@?

請高手幫看一下...

#include <iostream>
using namespace std;
int main()
{
    while(1)
    {
        int a[9][9];
        if(cin.eof())
        break;
        for(int i=0;i<9;i++)
        {
            for(int j=0;j<9;j++)
            {
                cin >> a[i][j];
                if(a[i][j]==0)
                return 0;
            }
        }
        bool r[10][9][9]={0},f=1;
        for(int k=1;k<10;k++)
        {
            for(int i=0;i<9;i++)
            {
                for(int j=0;j<9;j++)
                {
                    if(a[i][j]==k)
                    {
                        if(r[k][i][j])
                        {
                            f=0;
                            break;
                        }
                        else
                        {
                            for(int l=0;l<9;l++)  //將橫排作記
                            r[k][i][l]=1;
                            for(int l=0;l<9;l++)  //將直排作記
                            r[k][l][j]=1;
                            if(i<3&&j<3)          //1區作記
                            {
                                for(int l=0;l<3;l++)
                                {
                                    for(int m=0;m<3;m++)
                                    r[k][l][m]=1;
                                }
                            }
                            else if(i<3&&j>=3&&j<6)     //2
                            {
                                for(int l=0;l<3;l++)
                                {
                                    for(int m=3;m<6;m++)
                                    r[k][l][m]=1;
                                }
                            }
                            else if(i<3&&j>=6&&j<9)     //3
                            {
                                for(int l=0;l<3;l++)
                                {
                                    for(int m=6;m<9;m++)
                                    r[k][l][m]=1;
                                }
                            }
                            else if(i>=3&&i<6&&j<3)     //4
                            {
                                for(int l=3;l<6;l++)
                                {
                                    for(int m=0;m<3;m++)
                                    r[k][l][m]=1;
                                }
                            }
                            else if(i>=3&&i<6&&j>=3&&j<6)     //5
                            {
                                for(int l=3;l<6;l++)
                                {
                                    for(int m=3;m<6;m++)
                                    r[k][l][m]=1;
                                }
                            }
                            else if(i>=3&&i<6&&j>=6&&j<9)     //6
                            {
                                for(int l=3;l<6;l++)
                                {
                                    for(int m=6;m<9;m++)
                                    r[k][l][m]=1;
                                }
                            }
                            else if(i>=6&&i<9&&j<3)     //7
                            {
                                for(int l=6;l<9;l++)
                                {
                                    for(int m=0;m<3;m++)
                                    r[k][l][m]=1;
                                }
                            }
                            else if(i>=6&&i<9&&j>=3&&j<6)     //8
                            {
                                for(int l=6;l<9;l++)
                                {
                                    for(int m=3;m<6;m++)
                                    r[k][l][m]=1;
                                }
                            }
                            else if(i>=6&&i<9&&j>=6&&j<9)     //9
                            {
                                for(int l=6;l<9;l++)
                                {
                                    for(int m=6;m<9;m++)
                                    r[k][l][m]=1;
                                }
                            }
                        }
                    }
                    if(f==0)
                    break;
                }
                if(f==0)
                break;
            }
            if(f==0)
            break;
        }
        if(f==0)
        cout << "no\n";
        else if(f==1)
        cout << "yes\n";
    }
    return 0;
}

 
#1100: Re:輸出了額外的第八行


a613204 (a613204)

學校 : 中原大學
編號 : 1794
來源 : [210.242.135.125]
最後登入時間 :
2012-04-23 15:48:54
a016. 數獨(SUDOKU) | From: [118.161.168.87] | 發表日期 : 2008-12-24 22:45

我的也會耶

 
#1853: Re:輸出了額外的第八行


s88058 (zero)

學校 : 國立彰化高級中學
編號 : 5089
來源 : [203.68.64.40]
最後登入時間 :
2018-01-09 16:43:53
a016. 數獨(SUDOKU) | From: [61.221.226.103] | 發表日期 : 2009-04-26 16:37

#include <iostream>
using namespace std ;

int main ()
{
    int a[10][10];
   
    while (1)
    {
      
        int k=1 ;
       
       
        for (int i1=0 ; i1<9 ; i1++)
        {
            for (int i2=0 ; i2<9 ; i2++)
              cin >> a[i1][i2] ;
        }
    ***   if (cin.eof())
    ***      break ;
       
        if (k == 1)
          cout << "yes" << '\n' ;
        else if (k == 2)
          cout << "no" << '\n';
    }
   
    system ("pause") ;
    return 0 ;
}

#include <iostream>
using namespace std ;

int main ()
{
    int a[10][10];
   
    while (1)
    {
      
        int k=1 ;
        ***   if (cin.eof())
        ***     break ;
       
        for (int i1=0 ; i1<9 ; i1++)
        {
            for (int i2=0 ; i2<9 ; i2++)
              cin >> a[i1][i2] ;
        }
    
      
       
        if (k == 1)
          cout << "yes" << '\n' ;
        else if (k == 2)
          cout << "no" << '\n';
   
    }
   
    system ("pause") ;
    return 0 ;
}

結束輸出時,下面的會多輸出ㄧ個no(我也不知道為什麼,希望有心人士幫我解答)

所以把   if(cin.eof())   放在輸入的後面,應該就沒問題了吧!
              break;

 
ZeroJudge Forum