:
#include<iostream>
#include<iomanip>
#include<math.h>
#include<conio.h>
#include<String.h>
#include<ctype.h>
#include <stdlib.h>
#include<windows.h>
#include <fstream> //
using namespace std;
// :
struct Man
{
char sex; //
char FIO[80]; // , ,
int age; //
int height; //
int weight; //
char ycolor[20]; //
char hcolor[20]; //
};
int main()
{
if(SetConsoleCP(1251)==0)
{
cerr<<"Fialed to set codepage!"<<endl;
}
if(SetConsoleOutputCP(1251)==0)
{
cerr<<"Failed to set OUTPUT page!"<<endl;
}
fstream fl;
char fName[20];
cout <<" ";
cin.getline(fName,20);
fl.open(fName,ios::in);
if (!fl) cout<<" .\n";
if (fl)
{
char str[100];
cout <<" : \n";
while (!fl.eof())
{
fl.getline(str,100);
cout << str << endl;
}
// :
fl.seekg(0L, ios::beg); //
fl.clear();
Man person; /* , */
char fam[40], name[40], otch[40];
for(int i=0;i<80;i++)
cout << "=";
cout << endl;
// ,
char flag = 1; // ,
while (!fl.eof())
{
fl>>person.sex;
//
if (!fl.eof()) //
{
fl >> fam >> name >> otch;
// ,
// FIO:
strcat(fam," ");
strcat(fam,name);
strcat(fam," ");
strcat(fam,otch);
strcpy(person.FIO,fam);
// :
fl>>person.age>>person.height >> person.weight >> person.ycolor >> person.hcolor;
if (person.height > 180)
// ( > 180)
{
if (flag) cout<<
", > 180 :\n";
/* , , */
flag = 0; // ,
// :
cout <<" " << person.sex <<" : " << person.FIO << endl <<": " << person.age <<" : " << person.height <<" : " << person.weight <<" : " <<person.ycolor <<" : "<< person.hcolor << endl;
} // end if
} // end if
} // end while
if (flag) cout <<" , > 180 .\n";
} // end if
_getch();
|
|
return 0;
}
, , , .
7. , 1- , 2- 2- , 3- 2- .
string .
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <string>
#include <ctype.h>
#include <stdlib.h>
#include <windows.h>
#include <fstream> //
using namespace std;
int main()
{
if(SetConsoleCP(1251)==0)
{
cerr<<"Fialed to set codepage!"<<endl;
}
if(SetConsoleOutputCP(1251)==0)
{
cerr<<"Failed to set OUTPUT page!"<<endl;
}
ifstream fi1,fi2; //
ofstream fo; //
string sName1,sName2,sNameRez; //
do //
{
cout <<" ";
getline(cin,sName1);
basic_string<char>::size_type index;
//
// :
while((index=sName1.find(" "))!= string::npos)
sName1=sName1.replace(index,1, basic_string<char>(""));
} while(sName1.length()==0);
// ,
do
{
cout <<" ";
getline(cin,sName2);
basic_string<char>::size_type index;
// .
while((index=sName2.find(" "))!= string::npos)
sName2=sName2.replace(index,1, basic_string<char>(""));
}while(sName2.length()==0 || sName2.compare(sName1)==0);
/* , */
do
{
cout <<" ";
getline(cin,sNameRez);
basic_string<char>::size_type index;
// .
while((index=sNameRez.find(" "))!= string::npos)
sName2=sNameRez.replace(index,1, basic_string<char>(""));
} while(sNameRez.length()==0 ||(sNameRez.compare(sName1) ==0 || sNameRez.compare(sName2)==0));
fi1.open(sName1.c_str()); //
if(!fi1)
{
cerr<<" .\n";
return 1; //
}
fi2.open(sName2.c_str()); //
if(!fi2)
{
cerr<<" .\n";
fi1.close(); //
return 2;
}
fo.open(sNameRez.c_str()); //
if(!fo)
{
cerr<<" .\n";
fi1.close();//
fi2.close();//
return 3;
}
string str1,str2,str3="";
do
{
getline(fi1,str1);
getline(fi2,str2);
str3.clear();
int *map1=new int [256],*map2=new int [256];
//
for(int i=0;i<255;++i) //
map1[i]=map2[i]=0;
/* */
|
|
for(int i=0;i<str1.length();++i)
map1[static_cast<unsigned char>(str1[i])]++; //
for(int i=0;i<str2.length();++i)
map2[static_cast<unsigned char>(str2[i])]++;
for(int i=0;i<255;++i)
if(map1[i]&&map2[i])
// :
str3.push_back((char)(i));
//
// :
fo<<str1<<endl;
fo<<str2<<endl;
fo<<str3<<endl;
cout<<str1<<endl;
cout<<str2<<endl;
cout<<str3<<endl;
delete map1; //
delete map2;
}while(!fi1.eof()&&!fi2.eof()); //
fi1.close(); //
fi2.close();
fo.close();
_getch();
return 0;
}
8. , , 5- .
#include<iostream>
#include<iomanip>
#include<conio.h>
#include<string>
#include<ctype.h>
#include<stdlib.h>
#include<windows.h>
#include<fstream>
using namespace std;
int main()
{
if(SetConsoleCP(1251)==0)
{
cerr<<"Fialed to set codepage!"<<endl;
}
if(SetConsoleOutputCP(1251)==0)
{
cerr<<"Failed to set OUTPUT page!"<<endl;
}
ifstream fi1,fi2;
ofstream fo;
string sName1,sName2,sNameRez; //,
do //
{
cout <<" ";
getline(cin,sName1);
basic_string<char>::size_type index;
// .
while((index=sName1.find(" "))!=string::npos)
sName1=sName1.replace(index,1, basic_string<char>(""));
}while(sName1.length()==0);
do
{
cout <<" ";
getline(cin,sName2);
basic_string<char>::size_type index;
// .
while((index=sName2.find(" "))!=string::npos)
sName2=sName2.replace(index,1, basic_string<char>(""));
}while(sName2.length()==0 || sName2.compare(sName1)==0);
do
{
cout <<" ";
getline(cin,sNameRez);
basic_string<char>::size_type index;
// .
while((index=sNameRez.find(" "))!=string::npos)
sName2=sNameRez.replace(index,1, basic_string<char>(""));
}while(sNameRez.length()== 0 || (sNameRez.compare(sName1)==0 || sNameRez.compare(sName2)==0));
fi1.open(sName1.c_str()); //
if(!fi1)
{
cerr<<" .\n";
return 1;
}
fi2.open(sName2.c_str()); //
if(!fi2)
{
cerr<<" .\n";
fi1.close(); //
return 2;
}
fo.open(sNameRez.c_str());
//
if(!fo)
{
cerr<<" .\n";
fi1.close(); //
fi2.close();
return 3;
}
string str1,str2,str3="",sub1,sub2;
// ,
do
{
getline(fi1,str1);
getline(fi2,str2);
str3.clear();
fo<<str1<<endl;
fo<<str2<<endl;
cout<<str1<<endl;
cout<<str2<<endl;
basic_string<char>::size_type ind1;
//
basic_string<char>::size_type ind2;
// ,
|
|
do
{
ind1=str1.find(" ");
//
//
while(ind1==0 && ind1!= string::npos)
//
{
str1=str1.replace(0,1,"");
//
ind1=str1.find(" ");
//
}
// :
if(ind1!=string::npos)
//
{
sub1=str1.substr(0,ind1);
//
str1=str1.replace(0,ind1,"");
//
}
else //
{
sub1=str1.substr(0,str1.length());
//
str1=str1.replace(0,str1.length(),"");
//
}
//
ind2=str2.find(" ");
while(ind2==0&&ind2!=string::npos)
{
str2=str2.replace(0,1,"");
ind2=str2.find(" ");
}
if(ind2!=string::npos)
{
sub2=str2.substr(0,ind2);
str2=str2.replace(0,ind2,"");
}
else
{
sub2=str2.substr(0,str2.length());
str2=str2.replace(0,str2.length(),"");
}
if(max(sub1.length(),sub2.length())>5)
//
{
str3.append((sub1.length()<sub2.length())?("["+sub2+"] "):("["+sub1+"] ")); /* */
}
else //
{
str3.append((sub1.length() < sub2.length())? sub2+" ": sub1+" "); //
}
}while(str1.length()||str2.length());
fo<<str3<<endl;
cout<<str3<<endl;
}while(!fi1.eof()&&!fi2.eof());
fi1.close(); //
fi2.close();
fo.close();
_getch();
return 0;
}