# 北京航空航天大学 2012年复试下机题 解题报告

www.myexceptions.net  网友分享于：2013-02-20  浏览：1次

===============================

15 = 1 + 2＋3＋4＋5
15 = 4 + 5 + 6
15 = 7 + 8

15
16

1 2 3 4 5
4 5 6
7 8
NONE

```#include <stdio.h>
main()
{
int i, j, k, l, m, n, temp;
bool fail;
while( scanf("%d",&n) == 1 ){
fail = 1;
m = 2 * n;
l = n / 2;
//cout << m << " " << l << endl;
for( i=1; i<=l; i++ ){
for( j=i+1; j<n; j++ ){
temp = (i+j)*(j-i+1);
//cout << temp << endl;
if( temp > m )  break;
if( temp == m ){
fail = 0;
for( k=i; k<=j; k++ )
printf("%d ",k);
puts("");
}
}
}
if(fail) puts("NONE");
}
}```

1 1 1 1 1 1
1 1 0 0 0 1
1 0 0 0 1 0
1 1 0 1 1 1
0 1 0 1 0 0
1 1 1 1 1 1

6
1 1 1 1 1 1
1 1 0 0 0 1
1 0 0 0 1 0
1 1 0 1 1 1
0 1 0 1 0 0
1 1 1 1 1 1

8

```#include<stdio.h>
int a[100][100];

main()
{
int i, j, k, l, m, n;
freopen("2012_2_island.txt","r",stdin);//

while( scanf("%d",&n)==1 ){
l = n+2;
for( i=0; i<l; i++ )
for( j=0; j<l; j++ ){
if(i==0 || j==0 || i==n+1 || j==n+1) a[i][j] = 1;
else scanf("%d",&a[i][j]);
}

for( i=1, m=0; i<=n; i++ )
for( j=1; j<=n; j++ ){
if( a[i][j] == 0 ){
if( a[i+1][j]==1 && a[i-1][j]==1 || a[i][j+1]==1 && a[i][j-1]==1 )
m++;
}
}

printf("%d\n",m);
}
}```

#include <stdio.h> int main() {int i = 0; if(i == 0) printf("YES"); return 0;}
#include <stdio.h> int main() {int ifwhile = 0; int forif = 1;char if_for_while = 'a';char *str = "while"; while(ifwhile == 0) {ifwhile = 1;forif = 0;} if(forif == 0) {if_for_while = 'b';} if(ifwhile == 1) {if_for_while = 'c';} return 0;}

if:43
while:88
if:133
if:170

```#include <string.h>
#include <stdio.h>
char s[302];

main()
{
int i, j, k, l, m, n, w;
freopen("2012_3_string.txt","r",stdin);//
bool valid;
i = 0, w = 0;
while( gets(s) ){
l = strlen(s);
//cout << l << endl;
valid = 1;
for(i=0;i<l;i++){
if( s[i] == '"' ) valid = 1 - valid;	//遇到双引号
if( !valid ) continue;
if( s[i] == 'i' ){
if( s[i+1] == 'f'
&& ( s[i+2] == ' ' || s[i+2] == '(' )
&& ( s[i-1] == ' ' || s[i-1] == ';' ) )
printf("if:%d\n",i+1);
}
else if( s[i] == 'w' ){
if( s[i+1] == 'h' && s[i+2] == 'i' && s[i+3] == 'l' && s[i+4] == 'e'
&& ( s[i+5] == ' ' || s[i+5] == '(' )
&& ( s[i-1] == ' ' || s[i-1] == ';' ) )
printf("while:%d\n",i+1);
}
else if( s[i] == 'f' ){
if( s[i+1] == 'o' && s[i+2] == 'e'
&& ( s[i+3] == ' ' || s[i+3] == '(' )
&& ( s[i-1] == ' ' || s[i-1] == ';' ) )
printf("for:%d\n",i+1);
}
}
}
}```