本文整理汇总了C++中vi::at方法的典型用法代码示例。如果您正苦于以下问题:C++ vi::at方法的具体用法?C++ vi::at怎么用?C++ vi::at使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vi
的用法示例。
在下文中一共展示了vi::at方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
int n, m;
while(true){
cin >> n >> m;
if(n == 0 && m ==0) break;
adj.assign(n,vi());
visitados.assign(n,0);
s.clear();
for(int k = 0; k < m; k++){
int principal, dependente;
cin >> principal >> dependente;
(adj.at(principal-1)).push_back(dependente-1);
}
for(int l = 0; l < n; l++){
if(visitados[l] == 0){
dfs(l);
}
}
string result;
for(int d = s.size()- 1 ; d > 0;d--){
stringstream ss;
ss << s.at(d);
result += ss.str() + " ";
}
stringstream ss;
ss << s.at(0);
result += ss.str();
cout << result << endl;
}
}
示例2: main
int main(int argc, char** argv)
{
cin.sync_with_stdio(false);
sieve(1000000);
//sieve(10000000);
int L, U;
while (cin >> L >> U)
{
//cout << L << " " << U << endl;
int min_dist = 1000000;
int max_dist = -1;
pair<int, int> closest;
pair<int, int> furthest;
for (int i = L; i <= U; ++i) // find all primes within range
{
if (is_prime(i))
{
_primes.push_back(i);
}
}
if (_primes.size() < 2)
{
cout << "There are no adjacent primes.\n";
}
else
{
for (int i = 0; i < _primes.size()-1; ++i) // iterate through all primes
{
int dist = _primes.at(i+1) - _primes.at(i);
//cout << "dist " << _primes[i] << " to " << _primes[i+1] << " = " << dist << endl;
if (dist < min_dist)
{
closest.first = _primes[i];
closest.second = _primes[i+1];
min_dist = dist;
}
if (dist > max_dist)
{
furthest.first = _primes[i];
furthest.second = _primes[i+1];
max_dist = dist;
}
//cout << _primes[i] << " ";
}
cout << closest.first << "," << closest.second << " are closest, "
<< furthest.first << "," << furthest.second << " are most distant.\n";
}
_primes.clear();
}
return 0;
}
示例3: dfs
void dfs(int u){
if(visitados.at(u) == 0){
//printf("dfs em %d\n", u);
visitados[u] = 1;
for(int i = 0; i < adj.at(u).size(); i++){
int vizinho = adj.at(u)[i];
if(!visitados[vizinho]){
dfs(vizinho);
}
}
//printf("adicionando %d ao stack\n", u+1);
s.push_back(u+1);
}
}