summaryrefslogtreecommitdiff
path: root/I_anno/Programmazione_2/exercises/cognomi-simili.cc
diff options
context:
space:
mode:
Diffstat (limited to 'I_anno/Programmazione_2/exercises/cognomi-simili.cc')
-rw-r--r--I_anno/Programmazione_2/exercises/cognomi-simili.cc53
1 files changed, 53 insertions, 0 deletions
diff --git a/I_anno/Programmazione_2/exercises/cognomi-simili.cc b/I_anno/Programmazione_2/exercises/cognomi-simili.cc
new file mode 100644
index 0000000..fa74a22
--- /dev/null
+++ b/I_anno/Programmazione_2/exercises/cognomi-simili.cc
@@ -0,0 +1,53 @@
+#include<iostream>
+#include<sstream>
+#include<fstream>
+
+using namespace std;
+
+string check(string s, char chs[], int n) {
+ if(s.length()<n) { cout << s << endl ;return "";}
+ int i;
+ for(i = 0; i < n-1; ++i) {
+ if(s.at(i) != chs[i])
+ return "";
+ }
+
+ if(s.at(i) == chs[i]) return "";
+
+ return s;
+}
+
+void get_chs(string s, char* chs, int n) {
+ if(s.length()<n) return;
+ for(int i = 0; i < n; ++i) {
+ chs[i] = s.at(i);
+ //cout << chs[i];
+ }
+
+ //cout << "*" << endl;
+}
+
+int main() {
+ ifstream in("input.txt");
+ ofstream out("output.txt");
+
+ for(int ts = 0; ts < 100; ++ts) {
+ int n;
+ string s;
+ in >> n >> s;
+ ++n;
+ char* chs = new char[n];
+ out << s << ' ';
+ get_chs(s, chs, n);
+ for(int i = 0; i < 2; ++i) {
+ in >> s;
+ out << check(s, chs, n);
+ get_chs(s, chs, n);
+ }
+ out << '\n';
+ }
+
+ in.close();
+ out.close();
+ return 0;
+}