User
Pass
2FA
 
 

Niste subiecte de bac

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Freakz Forum Index -> Trash Bin -> Trash -> Programming / Scripting / Database
Author Message1792
mitzu

[Freakazoid]



Status: Offline
(since 05-11-2015 23:41)
Joined: 19 Dec 2010
Posts: 2424, Topics: 431
Location: Bucuresti

Reputation: 376.9
Votes: 42

   
Post Posted: 17-11-2011, 19:07:08 | Translate post to: ... (Click for more languages)

ScrieÑi un program C/C++ care citeste de la tastaturã un numãr natural n (2≤n≤20) si apoi n
cuvinte distincte, fiecare fiind format din cel mult 20 de caractere, numai litere mici ale
alfabetului englez. La introducerea datelor, dupã fiecare cuvânt se tasteazã Enter. Programul
afiseazã pe ecran numãrul de cuvinte dintre ultimele n-1 citite, care se încheie cu primul
cuvânt citit.
Exemplu: dacã n=5 si cuvintele citite sunt:
oare
soarele
stropitoare
oarecare
cicoare
pe ecran se afiseazã 2 (deoarece cuvintele stropitoare si cicoare se încheie cu oare).


ce functie pot folosi sa caute chestia asta ? sau o combinatie ceva ..


ma gandeam sa folosesc functia STRSTR si daca " (strstr (sir[x],sir[1]))==strlen(sir[x])-strlen(sir[1])



-
-
-
-> Visit my GSM store <-

0 0
  
Back to top
View user's profile Send private message
thenewbye911

[Mentally Stable]



Status: Offline
(since 11-07-2013 19:40)
Joined: 28 Sep 2010
Posts: 22, Topics: 3
Location: Romania

Reputation: 53.9
Votes: 3

 
Post Posted: 04-12-2011, 16:49:20 | Translate post to: ... (Click for more languages)

Code:

#include <iostream>
#include <string.h>

using namespace std;

bool hasEnding (std::string const &fullString, std::string const &ending)
{
    if (fullString.length() >= ending.length()) {
        return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));
    } else {
        return false;
    }
}


int main(){
    int nr,answer=0;
    char sufix[30];
    char cuvant[30];
    cin>>nr;nr-=1;
    cin>>sufix;
    while(nr--){
        cin>>cuvant;
        if(hasEnding (cuvant, sufix)){
            answer++;
        }
    }
    cout<<answer;
}


0 0
  
Back to top
View user's profile Send private message
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Freakz Forum Index -> Trash Bin -> Trash -> Programming / Scripting / Database  


The time now is 06-10-2024, 16:29:19
Copyright info

Based on phpBB ro/com
B

 
 
 







I forgot my password


This message appears only once, so
like us now until it's too late ! :D
x