输出
1
3
4
2
4^2=6
7
4^7=3
16783992^7=16783999
6^7=1
4 2 6 7 3 16783999 1
在for
打印语句所在的内部*it^n
循环中,循环中的*it
始终采用其他值代替2。但是在下一个迭代器矢量循环中,正确需要2。代码哪里出问题了?
#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
void func(){
unsigned int l,i,q,n,x;
vector<unsigned int> v;
vector<unsigned int>::iterator it;
cin >> q;
cin >> n;
v.push_back(n);
for(i=0 ; i < (q-1) ; i++)
{
cin >> n;
v.push_back(n);
l = v.size();
for(it = v.begin() ; it < v.end() ; it++)
{
x = *it^n;
cout << *it << "^" << n << "=" << x;
v.push_back(x);
if(l==2)
{
break;
}
l--;
}
}
for(it = v.begin(); it < v.end(); it++)
{
cout << *it << " ";
}
}
int main()
{
int t;
cin >> t;
while(t--)
{
func();
}
return 0;
}