Untitled
unknown
c_cpp
3 years ago
2.5 kB
5
Indexable
#include <bits/stdc++.h>
using namespace std;
bool primeN (int n) {
bool isPrime = true;
if(n<=2) {
return false;
} else {
for (int i = 2; i <= n / 2; i++) {
if(n % i == 0) {
isPrime = false;
break;
}
}
}
return isPrime;
}
void ejercicio_uno() {
string cad = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
string w; cin >> w;
vector<int> sum;
for(int i = 0; i < w.length(); i++) {
sum.push_back(cad.find(w[i]) + 1);
}
cout << accumulate(sum.begin(), sum.end(), 0);
primeN(accumulate(sum.begin(), sum.end(), 0)) ? cout << "La palabra es un numero primo" : cout << "La palabra no es un numero primo";
}
void ejercicio_dos() {
int n1, n2; cin >> n1 >> n2;
int sum = 0;
for(int i = n1; i <= n2; i++) {
cout << i << '\t' << fmod(sqrt(i), 1.0) << '\t' << sqrt(i) << endl;
if( fmod(sqrt(i), 1.0) == 0 ) sum++;
}
}
void ejercicio_tres() {
int A, L; cin >> A >> L;
int counter = 0;
while(A < L) {
if(A % 2 == 0) {
A /= 2;
} else {
A = 3*A+1;
}
if( A == 1 ) break;
counter++;
}
cout << counter;
}
bool isPal(string w) {
string word = w;
reverse(w.begin(), w.end());
if(word == w) {
return true;
} else return false;
}
bool isReflexed(string w) {
map<char, char> v = {
{'E', '3'},
{'J', 'L'},
{'L', 'J'},
{'S', '2'},
{'Z', '5'},
{'2', 'S'},
{'3', 'E'},
{'O', '0'},
{'5', 'Z'}
};
string word = w;
string newWord;
for(int i = 0; i < word.length(); i++) {
if(v.count(word[i]) == 1 && !(isalpha(word[i]))) {
newWord += v[word[i]];
continue;
} else newWord += word[i];
}
string l = newWord;
reverse(newWord.begin(), newWord.end());
if(newWord == l) {
return true;
} else return false;
}
void ejercicio_cuatro() {
string w; cin >> w;
if(isPal(w) && isReflexed(w)) {
cout << "Es un palindromo reflejado";
}else if( isPal(w) ) {
cout << "Es un palindromo regular";
} else if (isReflexed(w)) {
cout << "Es una cadena reflejada";
} else {
cout << "No es ningun palindromo ni cadena reflejada";
}
}
int main() {
//int T; cin >> T;
//while(T--)
//ejercicio_uno();
//ejercicio_dos(1, 4);
//ejercicio_tres();
ejercicio_cuatro();
return 0;
}
Editor is loading...