这题只是一个简单的欧拉图判断 , 难点在于字符串的读取操作,由于必须全部用字符串都入数据 , 并且存在空格所以在读字符串时都用gets函数
代码:
#include
#include
#include
using namespace std;
int n , m;
int xy[110];
char gh[300];
int main()
{
while(true)
{
gets(gh);
if(strcmp(gh , "ENDOFINPUT") == 0)
break;
int i , j , x;
int sum = 0;
sscanf(gh+6 , "%d %d" , &m , &n);
memset(xy , 0 , sizeof(xy));
for(i = 0; i < n; i++)
{
gets(gh);
if(gh[0] == '\0')
continue;
//if(gh[0] == 'E')
break;
sscanf(gh , "%d" , &x);
xy[i] += 1;
xy[x] += 1;
sum += 1;
for(j = 1; j < strlen(gh) ; j++)
if(gh[j] == ' ')
{
++j;
sscanf(gh+j , "%d" , &x);
//
cout<<x<<endl;
xy[i] += 1;
xy[x] += 1;
sum += 1;
}
}
gets(gh);
//cout<<i<<endl;
x = 0;
for(i = 0; i < n; i++)
if(xy[i]%2)
x += 1 ;
if(x == 0 && m == 0)
printf("YES %d\n" , sum);
else
{
//cout<<xy[0]<<endl;
if(xy[0]%2 && xy[m]%2 && m && x == 2)
printf("YES %d\n" , sum);
else cout<<"NO"<<endl;
}
}
return 0;
}
代码:
#include
#include
#include
using namespace std;
int n , m;
int xy[110];
char gh[300];
int main()
{
}