abs | |
acos | |
asin | |
atan | |
atan2 | |
ceil | |
cos | |
random | 0 . |
exp | |
fabs | ( ) |
floor | |
fmod | |
frexp | . |
ldexp | |
log | |
log10 | 10 |
modf(x, p) | ( ) |
pow(x, y) | x y, xy |
sin | |
sinh | |
sqrt | |
tan | |
tanh |
6. 123456 int. * . .
#include <iostream>
using namespace std;
int main(){
setlocale (LC_ALL, "RUS");
int a = 123456;
cout<<a<<endl;
cout<<(a/100000);
cout<<(a/10000)%10;
cout<<(a/1000)%10;
cout<<"*";
cout<<(a/10)%10;
cout<<a%10;
cout<<endl;
return 0;
}
7. 541069 int. . .
#include <iostream>
using namespace std;
int main() {
setlocale (LC_ALL, "RUS");
int a = 541069;
int max = -99999;
int min = 99999;
cout << a << endl;
int d = a % 10;
if(max < d)
max = d;
cout << max << endl;
int b = (a / 100) % 10;
if(min > b)
min = b;
cout << min << endl;
return 0;
}
8. . 650123 int. : 1- 3; 2- 2; 3- 1; 4- 0; 5- 5; 6- 6. .
#include <iostream>
using namespace std;
int main(){
setlocale (LC_ALL, "RUS");
int a = 650123;
cout<<a<<endl;
cout<<"1 "<<a%10<<endl;
cout<<"2 "<<(a/10)%10<<endl;
cout<<"3 "<<(a/100)%10<<endl;
cout<<"4 "<<(a/1000)%10<<endl;
cout<<"5 "<<(a/10000)%10<<endl;
cout<<"6 "<<a/100000<<endl;
return 0;
}
9. . .
, .
|
|
int *p; // int
.
.
- , , , , . , C++. , .
:
int a;
a = 7;
int *mas = new int[a];
10. . , N , - . INPUT.TXT N . , N . :̻ - , :̻ - . , .
#include<iostream>
#include<fstream>
using namespace std;
int main(){
setlocale(LC_ALL,"Russian");
ifstream in("pks.txt");
char q;
int kol;
in>>kol;
int **mass, h, m;
mass = new int *[kol];
for(int i=0;i<kol;i++)
mass[i]=new int [2];
for (int i =0; i < kol; i++){
in>>h>>q>>m;
mass[i][0] = h*60+m;
in>>h>>q>>m;
mass[i][1] = h*60+m;
cout<<mass[i][0] << " " << mass[i][1]<<endl;
}
for (int i = 0; i < kol-1; i++)
if (mass[i][0] > mass[i+1][0]){
h = mass[i][0];
mass[i][0] = mass[i+1][0];
mass[i+1][0] = h;
h = mass[i][1];
mass[i][1] = mass[i+1][1];
mass[i+1][1] = h;
}
for (int i =0; i < kol; i++){
cout<<mass[i][0] << " " << mass[i][1]<<endl;
}
h = 0;
m = 0;
int max=0;
for (int i = 0; i < 1439; i++){
if (i == mass[m][0]) {
h++;
m++;
if (m == kol) break;
}
if (h > max) max = h;
for (int j = 0; j < kol; j ++)
if (i == mass[j][1]) h--;
}
cout<<max<<endl;
for (int i = 0; i < kol; i++) delete [] mass[i];
delete [] mass;
return 0;
}
11. . N
. , y . ( , . , .) , , , N .
#include<iostream>
#include<math.h>
using namespace std;
int main() {
int x1, x2, n, k;
int t1, t2;
int tmin=9999, tmax;
cin>>x1>>x2>>n;
if(x1<x2){
k=x1;
n--;
}
else {
k=x2;
n--;
}
|
|
for(int i=0; i<=n; i++){
t1=x1*i;
t2=x2*(n-i);
if (t1 < t2) tmax=t2;
else tmax=t1;
if(tmin > tmax) tmin=tmax;
}
cout<<tmin+k<<endl;
return 0;
}
12. ++. include, define.
++ , , , - . ++ ,
++ .
, #include. . , .
#define , . , . :
#define _ _
, . . .
, TRUE 1, a FALSE 0 :
#define TRUE 1
#define FALSE 0
, TRUE FALSE, 1 0 .
13. .
- C++ , , .
- , .
int A[10]; // int struct MyStruct { int A; char C[10]; }; MyStruct obj1[10]; // MyStruct // |
14. .
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int a[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
char r[][3] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
for(int i=0; i < 13; i++){
while(n>=a[i]){
cout<<r[i];
n-=a[i];
}
}
return 0;
}
15. .
#include<iostream>
using namespace std;
int main(){
char n[20];
cin>>n;
int a[] = {1000, 500, 100, 50, 10, 5, 1};
char r[] = {'M', 'D', 'C', 'L', 'X', 'V', 'I'};
int res[20];
for (int i = 0; i < 20; i++) res[i] = 0;
for (int i = 0; n[i]!= '\0'; i++) {
for (int j = 0; j < 7; j++)
if(r[j] == n[i]) res[i] = a[j];
}
int summ=0;
for (int i = 0; i < 19; i++){
if (res[i] < res[i+1])
summ-=res[i];
else
summ+=res[i];
}
cout<<summ<<endl;
for (int i = 0; i < 20; i++)
cout<<res[i]<< " ";
return 0;
}
16. ( 1755).
#include<iostream>
#include<math.h>
using namespace std;
int main() {
setlocale(LC_ALL, "Russian");
int a=1755;
long double res=1;
int m[5000];
for (int i=0; i<5000; i++){
m[i]=0;
m[0]=1;
}
for (int i=1;i<=a; i++){
for (int j=0; j<5000; j++){
m[j]*=i;
}
for (int j=0; j<5000;j++){
|
|
if (m[j]>10){
m[j+1]+=m[j]/10;
m[j]=m[j]%10;
}
}
}
bool b=true;
for (int i=4999;i>=0;i--){
if (m[i]==0 && b==true)
continue;
else
b=false;
cout<<m[i];
}
return 0;
}
17. , .
#include <iostream>
using namespace std;
int main() {
double a[3] = { 1, 2, 3 };
double b[3] = { 4, 5, 6 };
double c[3] = { 0 };
c[0] = a[1] * b[2] - a[2] * b[1];
c[1] = a[2] * b[0] - a[0] * b[2];
c[2] = a[0] * b[1] - a[1] * b[0];
cout << c[0] << " " << c[1] << " " << c[2] << " ";
return 0;
}
18. new.
New C++, . , new, new , , .
19. . .
++ , . , .
++ , : =.
- += -;
- -= -;
- *= -;
- /= -;
- %= - ;
20. for.
. , - . , , .
++ :
- for
- while
- do while
, (. . true).
// for:
for (1; ; 3){
/* */;
}
21. while.
while while, , while .
true, , .
22. . a == b a!= b a > b a < b a >= b a <= b
23. . , ( ) , . , , . , , , .
24. . . , ( ) 2 : 3 C++: void func1 (int arg); void func2 (int * arg); void func3 (int & arg);
25. . , , . . ( , - .) , . , . -, , :
26. .
, , char int. float, double, long double, void . |
4.3.
~ | ~expr | |
<< | expr1<<expr2 | |
>> | expr1>>expr2 | |
& | expr1 & expr2 | |
^ | expr1 ^ expr2 | |
| | expr1 | expr2 | |
&= | expr1 &= expr2 | |
^= | expr1 ^= expr2 | |
|= | expr1 |= expr2 | |
<<= | expr1 <<= expr2 | |
>>= | expr1 >>= expr2 |
27. . , , .
#include <iostream>
using namespace std;
void main() {
setlocale(LC_ALL, "Russian");
char str[2000];
cin.getline(str, 2000);
out << endl;
int a[256];
for (int i = 0; str[i]; i++) {
a[str[i]]++;
}
for (int i = 0; i < 256; i++) {
if (a[i])
cout << " " << char(i) << " " << a[i] << " " << endl;
}
system("pause");
}
28. ++
++ , .
.
. , , .