All pastes #401378 Raw Edit

Untitled

public cpp v1 · immutable
·published 2007-03-19 09:34 UTC
rendered paste body
#include <iostream>#include <fstream>#include <string>using namespace std;int main(int argc, char *argv[]){    char ch;    do{        //Adatbevitel modja        int v;        if(argc>1){            cout<<"Az adatbevitel a parameterkent adott filebol tortenik"<<endl;            v=1;        }else{            cout<<"Kerlek add meg az adatbevitel modjat!"<<endl                <<"   (1) Adatbevitel szoveges filebol"<<endl                <<"   (2) Adatbevitel billentyuzetrol"<<endl;            do{                cout<<":";                string mode;                cin>>mode;                v=atoi(mode.c_str());                if(v==0) cout<<"Csak 1es es 2es irhato be!"<<endl;            }while(v!=1 && v!=2);        }        //Beolvasas        int* t;//        int n=0;        string sorok;        ifstream szfile;        switch(v){            case 1:                //Ha az adatbevitel szoveges filebol tortenik                if(argc<=1){                        string fname;                        cout<<"Add meg a szoveges file nevet: ";                        cin>>fname;                        szfile.open(fname.c_str());                } else szfile.open(argv[1]);                //Hiba eseten:                if(szfile.fail()){                        cout<<"Hibas file nevet adtal meg!";                        char c; cin>>c;                        exit(1);                }                //A beolvasas://                szfile >> n;//                t = new int[n];//              for(int i=0;i<n;i++){                    szfile >> sorok;                    if(sorok=="") continue;                    t[i]=atoi(sorok.c_str());                    if(t[i]==0) cout<<"A file 0-t vagy nem csak szamokat tartalmaz!";                }                break;            case 2:                //Beolvasas billentyuzetrol                do{                    cout<<"Add meg a szamok darabszamat: ";                    string be;cin>>be;                    n=atoi(be.c_str());                    if(n==0) cout<<"Nullanal nagyobb szamot kell beirni!"<<endl;                } while(!(n>0));                t=new int[n];                string be;                int szam;                for(int i=0;i<n;i++){                    do{                        cout<<"Kerlek add meg a(z) "<<i+1<<"-dik szamot: ";                        cin>>be;                        szam=atoi(be.c_str());                        if(szam<=0 || (szam==0 && be!="0")){                            cout<<"0-t vagy nem szamot adtal meg!"<<endl;                        }else t[i]=szam;                    } while( szam<=0 || (szam==0 && be!="0"));                }                break;        }        cout<<"Kerlek add meg k-t: ";        int k;cin>>k;        //Kiertekeles        bool l=false;        int i,min;        for(int j=0;j<=n;++j){            if(t[j]%k==0 && !l){                l=true;                i=j+1;                min=t[j];            }            if(t[j]%k==0 && l && t[j]<=min){                i=j;                min=t[j];            }        }        cout<<"A vektor legkisebb k-val oszthato szama: "<<min<<" amit a "<<i<<"-dik helyen vesz fel"<<endl;        char c;cin>>c;        cout<<"Futassam ujra?(i/n) ";        cin>>ch;    }while(ch!='n' && ch!='N');    return 0;}