此题把题意弄懂后就很容易,S顺时针走,E逆时针走,确定一个分割点该处两人相遇时途经的客人数之和相等,直接枚举。 #include <iostream> using namespace std; //s顺时针走,e逆时针走,问他们在哪里相遇时路径上面经过的数字之和相等 //直接用枚举法 int main(){ int table[32]; int n,sum1,sum2,i,j; while(cin>>n,n!=0){ for (i = 1;i <= n;i++) cin>>table[i]; for (i = 1;i <= n;i++) { sum1 = 0; sum2 = 0; for (j = 1;j <= i;j++) sum1 += table[j]; for (j = n;j > i;j--) sum2 += table[j]; if (sum1 == sum2) { cout<<"Sam stops at position "<<i<<" and Ella stops at position "<<i+1<<"."<<endl; break; } } if (sum1 != sum2) { cout<<"No equal partitioning."<<endl; } } return 0; }