Am si eu nevoie de ajutor la o problema in C++,
Se citeste un sir de caractere si sa se afiseze cate vocale consecutive se afla in sir
Si inca una la care am niste dubii deoarece nu afiseaza chiar ce trebuie la toate numerele.
Se citeste un numar n sa se afiseze cel mai mic numar m format din cifrele lui n cu proprietatea ca m>n.
Multumesc
rezolvare C++
Moderators: Moderatori ajutatori, Moderatori
- Ozone
- Membru, skill +2
- Posts: 626
- Joined: 06 Dec 2008, 14:45
- Detinator Steam: Da
- CS Status: Play hard , or go home !
- Detinator server CS: Nu!
- Location: Mioveni / Arges
- Has thanked: 3 times
- Been thanked: 12 times
Pentru a doua problema ce trebuie sa modific in urmatorul program? Deoarece la numere ca 1432 imi arata 4132 si acesta nu este cel mai micnumar.
Code: Select all
#include <iostream.h>
int main(){
int n,m,a[100],i,aux=0,j,ok=0;
cin>>n;
m=0;
aux=n;
while(aux){
i++;
a[i]=aux%10;
aux=aux/10;
}
while(ok=0)
for(j=1;j<=i;j++)
if(a[i]>a[i+1]){
aux=a[i];
a[i]=a[i+1];
a[i+1]=aux;
ok=1;
}
for(j=i;j>=1;j--)
m=m*10+a[i];
cout<<m;
}
Last edited by Ozone on 20 Nov 2013, 15:52, edited 1 time in total.
- MCosti
- Fost moderator
- Posts: 2251
- Joined: 28 Sep 2008, 06:58
- Detinator Steam: Da
- Reputatie: Membru Club eXtreamCS (2 luni)
Fost moderator
Nume anterior: DjMax - Has thanked: 139 times
- Been thanked: 60 times
- Contact:
De o ora ma chinui sa fac algoritmul la prima problema si tot nu-mi iese :)))
Cand imi iese revin cu un edit.
Cand imi iese revin cu un edit.
- Ozone
- Membru, skill +2
- Posts: 626
- Joined: 06 Dec 2008, 14:45
- Detinator Steam: Da
- CS Status: Play hard , or go home !
- Detinator server CS: Nu!
- Location: Mioveni / Arges
- Has thanked: 3 times
- Been thanked: 12 times
Am reusit sa fac intr-un final prima problema.
Code: Select all
#include <iostream>
#include <string.h>
using namespace std;
int main(){
char a[100],voc[]="aeiouAEIOU";
int nr=0,i;
cin.get(a,100);
for(i=0;i<strlen(a)-1;i++){
if(strchr(voc,a[i])!=NULL && strchr(voc,a[i+1])!=NULL){
if(strchr(voc,a[i+1])!=NULL && (strchr(voc,a[i+2])==NULL ||a[i+2]==NULL))
nr=nr+1;
nr=nr+1;}
}
cout<<nr;
}
- Ozone
- Membru, skill +2
- Posts: 626
- Joined: 06 Dec 2008, 14:45
- Detinator Steam: Da
- CS Status: Play hard , or go home !
- Detinator server CS: Nu!
- Location: Mioveni / Arges
- Has thanked: 3 times
- Been thanked: 12 times
Imi puteti spune si mie ce e gresit in rezolvarea aceasta? Am vrut sa fac doar un inceput de program ca o idee. Daca primul cuvant incepe cu o vocala sa se adauge un alt cuvant dupa el( intre el si al doilea).
Code: Select all
#include <iostream>
#include <string.h>
using namespace std;
int main(){
char a[100],*aux,voc[]="aeiouAEIOU",b[100];
cin.get(a,100);
cin.get();
cin.get(b,100);
if(strchr(voc,a[0])!=NULL){
aux=strchr(a,' ');
strcpy(a+(aux-a),b);
strcpy(a+(aux-a)+strlen(b),aux);
}
cout<<a;
}
- farkinsen
- Membru, skill +1
- Posts: 151
- Joined: 28 May 2011, 15:34
- Detinator Steam: Da
- CS Status: pauza
- Detinator server CS: Nu
- Reputatie: Utilizator neserios (tepar)
- Location: Ploiesti
- Has thanked: 12 times
- Been thanked: 5 times
- Contact:
Code: Select all
#include <iostream>
#include <string.h>
using namespace std;
int main(){
char a[100],c[100],*aux,voc[]="aeiouAEIOU",b[100];
cin.get(a,100);
cin.get();
cin.get(b,100);
if(strchr(voc,a[0])!=NULL){
aux=strchr(a,' ');
strcpy(c,a);
strcpy(a+1+(aux-a),b);
aux=strchr(c,' ');
strcpy(c,c+(aux-c));
strcat(a,c);
}
cout<<a;
}
- Ozone
- Membru, skill +2
- Posts: 626
- Joined: 06 Dec 2008, 14:45
- Detinator Steam: Da
- CS Status: Play hard , or go home !
- Detinator server CS: Nu!
- Location: Mioveni / Arges
- Has thanked: 3 times
- Been thanked: 12 times
Sau mai simplus am facut.
Code: Select all
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char b[100],v[100],*p;
cin.get(v,100);
cin.get();
cin.get(b,100);
if(strchr("aeiouAEIOU",v[0])!=NULL){
p=strchr(v,' ');
strcpy(v+(p-v)+1,strcat(b,p));}
cout<<v;
}
-
- Information
-
Who is online
Users browsing this forum: Bing [Bot], Coka Cola, GENERALU', SoLoz0rNNN, trekA and 316 guests