.
#include<iostream>
#include<windows.h>
#include<iomanip>
#include<math.h>
#include<conio.h>
#include<String.h>
#include<ctype.h>
#include <stdlib.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 ifl; //
char ch;
char name[20]; //
do /* , , */
{
int i = 0; //
cout<<" : ";
while ((ch = _getche())!= '\r') /* <Esc> (, ) */
{
if (ch == 27) exit(0);
else name[i++] = ch;
}
cout<<"\n";
name[i] = '\0';
ifl.open(name,ios::in); //
if(ifl==0)
// ,
{
cout<<" !\n"; ch = _getch();
if (ch==27) exit(0); /* , */
}
} while (!ifl); //
if (ifl) // , :
{
int val; // ,
int count1=0; //
int count2=0;
int count3=0;
int count4=0;
int count5=0;
int count6=0;
while (!ifl.eof()) //
{
val=ifl.get(); // 1
/* , , : */
switch (val)
{
case '[': count1++; break;
case ']': count2++; break;
case '(': count3++; break;
case ')': count4++; break;
case '{': count5++; break;
case '}': count6++;
}
}
cout << "[=" << count1 << endl;
cout << "]=" << count2 << endl;
cout << "(=" << count3 << endl;
cout << ")=" << count4 << endl;
cout << "{=" << count5 << endl;
cout << "}=" << count6 << endl;
_getch();
}
return 0;
}
2. , ( )
, . , .
#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;
|
|
int main()
{
if(SetConsoleCP(1251)==0)
{
cerr<<"Fialed to set codepage!"<<endl;
}
if(SetConsoleOutputCP(1251)==0)
{
cerr<<"Failed to set OUTPUT page!"<<endl;
}
ifstream inf; //
ofstream outf; //
char ch; // ,
char name1[81]; //
char name2[81]; //
cout<<" , : ";
cin >> name1;
inf.open(name1); //
if (!inf) //
cout<<" ";
else
{
cout << " a, : ";
cin >> name2;
outf.open(name2); //
inf.seekg(-1L, ios::end); /* . , L . , , 3L */
do /* , */
{
inf.get(ch); //
if (ch == '\n') inf.seekg(-1L, ios:: cur);
/* : \r\n, : \n, \n, */
outf << ch; //
cout << ch; //
inf.seekg(-2L, ios::cur); /* ( , , , */
} while (!inf.fail()); /* , fail() 1 */
cout << endl; //
outf << endl; //
inf.close(); outf.close(); //
}
_getch();
return 0;
}