diff options
author | Santo Cariotti <sancn@live.com> | 2017-04-26 16:37:39 +0200 |
---|---|---|
committer | Santo Cariotti <sancn@live.com> | 2017-04-26 16:37:39 +0200 |
commit | 483d63fa7249ad8d6020680c48c3cf6df35010b3 (patch) | |
tree | 2f8649e3ae6b42ace5011246285c9c450f004222 /cpp/numeri.cc | |
parent | 6c957dc4e01aee6ce9cae3c8342d04b0fd9ca9c4 (diff) |
Moved all C++ files into CPP folder
Diffstat (limited to 'cpp/numeri.cc')
-rw-r--r-- | cpp/numeri.cc | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/cpp/numeri.cc b/cpp/numeri.cc new file mode 100644 index 0000000..ec2d2d4 --- /dev/null +++ b/cpp/numeri.cc @@ -0,0 +1,50 @@ +#include <iostream> +#include <fstream> + +using namespace std; + +int main(void) +{ + fstream file; + file.open("dati.dat"); + + typedef unsigned short int size_t; + + size_t a, b, c, seq = 0, tot = 0, num; + char stringa[] = "12312312312"; + char l; + while(true) + { + cout << "3 numeri: "; + cin >> a >> b >> c; + if(a >= 0 && a <= 9 && b >= 0 && b <= 9 && c >= 0 && c <= 9){ + if(a != b && b != c && a != c) break; + } + } + + file << a << endl; + file << b << endl; + file << c << endl; + file << stringa << endl; + file.seekg(5, file.beg); + + while(!file.eof()) + { + file.get(l); + num = l - '0'; + if(seq == 0) { + if(num == a) seq++; + } else if(seq == 1) { + if(num == b) seq++; + } else if(seq == 2) { + if(num == c) seq++; + } + + if(seq == 3) { tot++; seq = 0; } + } + + cout << "\n" << tot; + file.close(); + + return 0; +} |