問題描述 :
給出一個包含n個整數的數列,問整數a在數列中的第一次出現是第幾個。
輸入格式
第一行包含一個整數n。
第二行包含n個非負整數,爲給定的數列,數列中的每個數都不大於10000。
第三行包含一個整數a,爲待查找的數。
輸出格式
如果a在數列中出現了,輸出它第一次出現的位置(位置從1開始編號),否則輸出-1。
樣例輸入
6
1 9 4 8 3 9
9
樣例輸出
2
數據規模與約定
1 <= n <= 1000。
#include <iostream>
using namespace std;
int main()
{
int word[10000];
int number;
while(cin>>number && number!=0)
{
for(int i=1; i<=number; i++)
{
cin>>word[i];
}
int theNumber;
cin>>theNumber;
int i;
for( i=1; i<=number; i++)
{
if(word[i]==theNumber) //找到匹配
{
cout<<i;
break;
}
}
//沒有匹配時
while(i==number+1 && word[i]!=theNumber)
{
cout<<"-1";
break;
}
}
return 0;
}
是哪裏出錯了呢?就是通不過 鬱悶 (▔﹏▔)