Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <vector>
- using namespace std;
- int contatore(char n){
- int sentinella0 = 0;
- int sentinella1 = 0;
- if (n == '0'){
- sentinella0++;
- }
- if (n == '1'){
- sentinella1++;
- }
- return sentinella0, sentinella1;
- }
- //La sentinella0 da valori casuali
- int main()
- {
- string testo = "";
- int lunghezza_testo;
- cout << "Inserire il testo da analizzare" << endl;
- getline(cin, testo);
- lunghezza_testo = testo.size();
- cout << "Il testo รจ lungo " << lunghezza_testo << endl;
- int sum_0, sum_1 = 0;
- for (char n : testo)
- {
- int temp0, temp1 = 0;
- temp0, temp1 = contatore(n);
- sum_0 += temp0;
- sum_1 += temp1;
- }
- vector<int> results = {sum_0, sum_1};
- for (auto elemento : results)
- {
- cout << elemento << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment