ADV-143 扶老奶奶过街
问题描述:
C语言代码:
#include <stdio.h>
int main(){
int r[5]={0};
int i,sum;
for(i=0;i < 5;i++){
r[i]=1;
sum=0;
if(r[0]==0 && r[4]==0)
sum++;
if(r[2]==1 || r[4]==1)
sum++;
if(r[2]==1 || r[3]==1)
sum++;
if(r[1]==0 && r[2]==0)
sum++;
if(r[4]==0)
sum++;
if(sum==2){
switch(i){
case 0: printf("A "); break;
case 1: printf("B "); break;
case 2: printf("C "); break;
case 3: printf("D "); break;
case 4: printf("E "); break;
}
}
r[i]=0;
}
return 0;
}
java代码:
public class Main {
public static void main(String[] args) {
int r;
for(int i=1;i<=5;i++){
r=0;
if(i!=1&&i!=5){
r++;
}
if(i==3||i==5){
r++;
}
if(i==3||i==4){
r++;
}
if(i!=2&&i!=3){
r++;
}
if(i!=5){
r++;
}
if(r==2){
System.out.print((char)(i-1+'A')+" ");
}
}
}
}