alphacademy-cpp/hf2/hf6/1.cpp

47 lines
991 B
C++
Raw Normal View History

2022-11-22 17:59:11 +00:00
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int convert(string a) {
int out = 0;
int counter = 1;
//cout<<a<<endl;
for (int i = a.size() - 1; i > 0; i--) {
if(a[i] == '1' ) {
out += counter;
//cout<<"found one at "<< a[i] ;
}
//cout<< " current index "<< i <<" at character "<<a[i]<< " counter " << counter<<" current output " << out<<endl;
counter *= 2;
}
return out;
}
string convertToBase(int n, int base) {
string out;
return out;
}
int returnVecMax(vector<int> a) {
int out = a[0];
for (int i =1; i < a.size(); i++) {
if (a[i] > out) {
out = a[i];
}
}
return out;
}
int main() {
vector<int> test;
test.push_back(2);
test.push_back(6);
test.push_back(-7);
test.push_back(1);
test.push_back(0);
test.push_back(1);
test.push_back(4);
cout<<returnVecMax(test)<<endl<<convert("0101101");
}