1052.找x
- 题目描述:
- 
输入一个数n,然后输入n个数值各不相同,再输入一个值x,输出这个值在这个数组中的下标(从0开始,若不在数组中则输出-1)。 
- 输入:
- 
测试数据有多组,输入n(1<=n<=200),接着输入n个数,然后输入x。 
- 输出:
- 
对于每组输入,请输出结果。 
- 样例输入:
- 
2 1 3 0 
- 样例输出:
- 
-1 
#include<iostream> using namespace std; int main(){ int n,x,i; int a[201]; while(cin>>n){ for(i=0;i<n;i++){ cin>>a[i]; } cin>>x; int pos=-1; for(i=0;i<n;i++) { if(a[i]==x) pos=i; } cout<<pos<<endl; } return 0; }
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号