Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cmath>
- #include <stdio.h>
- #include <stdlib.h>
- using namespace std;
- ifstream fin("f.in");
- ofstream fout("f.out");
- unsigned int SumCif(int n) {
- //cout << n << "\t" << (n % 10) << "\t" << abs(n % 10) << "\n";
- //printf("%d\t%d\t%d\n", n, (n % 10), (int)abs(n % 10));
- if(!n) return 0;
- else return abs(n % 10) + SumCif(n / 10);
- }
- unsigned int SumCif2(int n) {
- int s = 0;
- while(n) {
- //cout << n << "\t" << (n % 10) << "\t" << abs(n % 10) << "\n";
- //printf("%d\t%d\t%d\n", n, (n % 10), (int)abs(n % 10));
- s += abs(n % 10);
- n /= 10;
- }
- return s;
- }
- unsigned int NrMax(int n) {
- int nr = 0;
- int cif[10] = {0};
- while(n) {
- cif[ (int)abs(n % 10) ]++;
- n /= 10;
- }
- for(int i = 9; i >= 0; i--)
- for(int j = cif[i]; j > 0; j--)
- nr = nr * 10 + i;
- return nr;
- }
- bool Palindrom(int n) {
- int cif = 0;
- int n2 = n = (int)abs(n);
- while(n2) {
- cif++;
- n2 /= 10;
- }
- int c1, c2;
- while(n) {
- c1 = n % 10;
- c2 = n / pow(10, (cif - 1));
- cout << n << "\t" << c1 << "\t" << c2 << "\t" << cif << "\n";
- if(c1 != c2) return false;
- n %= (int)pow(10, (cif - 1));
- n /= 10;
- cif -= 2;
- }
- return true;
- }
- bool Par(int n) {
- return !(n % 2);
- }
- bool Prim(int n) {
- if(n <= 1) return false;
- for(int i = 2; i <= n / 2; i++)
- if(!(n % i)) return false;
- return true;
- }
- bool PatrPerf(int n) {
- return (sqrt(n) * sqrt(n) == n);
- }
- bool Sir(int *s, int n) {
- for(int i = 1; i < n; i++)
- fout << s[i] << "\t" << ((Par(s[i])) ? "PAR" : "IMPAR") << "\t" << (Prim(s[i]) ? "PRIM" : "NEPRIM") << "\t" << (PatrPerf(s[i]) ? "PATRAT PERFECT" : "NOPE") << "\n";
- }
- int main() {
- int x;
- //while(fin >> x) cout << SumCif(x) << "\n\n";
- //while(fin >> x) printf("%d\n\n", SumCif2(x));
- //for(int i = 1; i <= 64; i++) printf("%d\t%o\t%x\t%p\n", i, i, i, i);
- //cout << (unsigned int)-1;
- //while(fin >> x) fout << NrMax(x) << "\n";
- //while(fin >> x) fout << Palindrom(x) << "\n";
- int sir_n = 0;
- int *sir, *sir_aux;
- sir = sir_aux = NULL;
- while(fin >> x) {
- sir_n++;
- if(!(sir = (int*) realloc (sir, sir_n * sizeof(int)))) return -1;
- //sir = (int*) realloc (sir, sir_n * sizeof(int));
- sir[sir_n - 1] = x;
- }
- Sir(sir, sir_n);
- free(sir);
- free(sir_aux);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement