43 lines
733 B
C++
43 lines
733 B
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
Classe: 3AIN
|
|
Data: 07/03/2025
|
|
|
|
es5C: Scrivere una funzione che ricevuta in input
|
|
una stringa str, duplichi le occorrenze di ogni cifra.
|
|
Prototipo richiesto:
|
|
char *dupdigits(char * const str);
|
|
Esempio:
|
|
"12 ottobre 1492" -> "1122 ottobre 11449922"
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <cstring>
|
|
|
|
#define SIZE 100+1
|
|
|
|
using namespace std;
|
|
|
|
char *dupdigits(char * const str);
|
|
|
|
int main(void) {
|
|
char str[SIZE];
|
|
|
|
cin.getline(str, SIZE);
|
|
|
|
cout << dupdigits(str);
|
|
|
|
return 0;
|
|
}
|
|
|
|
char *dupdigits(char * const str) {
|
|
for (int i = 0; str[i] != '\0'; i++) {
|
|
if (isdigit(str[i])) {
|
|
memmove(str + i + 1, str + i, strlen(str) + 1);
|
|
i++;
|
|
}
|
|
}
|
|
|
|
return str;
|
|
} |