web123456

Oriental Boyi oj partial answer

East BoyleojSome of the answers, the editorial is updated once a week! (Copy the answers consciously quit!)

1015:Getting Started] The Chicken and Rabbit Problem

Title Description

lit. chicken and rabbit in the same cageProblem: A cage contains a number of chickens and a number of rabbits. There are 50 heads and 160 legs. How many chickens and rabbits are there in each cage?

exports

Two integers on one line.

Number of chickens Number of rabbits separated by spaces!

Sample Input

not have

Sample Output

One line, one integer.

  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. for(int i=1;i<=80;i++){
  5. for(int j=1;j<=40;j++){
  6. if(i+j==50&&i*2+j*4==160){
  7. cout<<i<<" "<<j;
  8. }
  9. }
  10. }
  11. return 0;
  12. }

1016:[Getting Started] Buying Kittens and Puppies

Title Description

An animal breeding center earmarks $X to purchase two small animals, puppies ($A each) and kittens ($B each).

Request earmarks, (at least one each for cats and dogs), just in time to use them up? Request the total number of programs. If not, please output 0.

importation

Enter a line with only three integers. X,A,B. ( 100 < X < 32768; 1 <= A, B <= 100 )

exports

The output is only one line (which means there is a carriage return symbol at the end) and consists of 1 integer.

Sample Input
1700 31 21
Sample Output
3
  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. int x,a,b,cnt=0;
  5. cin>>x>>a>>b;
  6. for(int i=1;i<x/a;i++){
  7. for(int j=1;j<x/b;j++){
  8. if((i*a+j*b)==x){
  9. cnt++;
  10. }
  11. }
  12. }
  13. cout<<cnt;
  14. return 0;
  15. }

1017:Getting Started] Finding the number of parts

Title Description

There is a pile of more than 100 parts; if you count three by three, there are two left; if you count five by five, there are three left; if you count seven by seven, there are five left. Can you write a program to calculate at least how many parts are in the pile?

importation

not have

exports

One line, one integer.

  1. #include <iostream>
  2. using namespace std;
  3. int main(){
  4. for(int i=101;i<200;i++){
  5. if(i%3==2&&i%5==3&&i%7==5){
  6. cout<<i<<endl;
  7. break;
  8. }
  9. }
  10. return 0;
  11. }

1020:[Getting Started] What is the sum of

Title Description

Input a three-digit positive integer and add it to its inverse to output the sum.

E.g. if you enter 167, the sum is 167+761=928

importation

Only one line, a three-digit positive integer.

exports

A positive integer

Sample Input
167
Sample Output
928
  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. int a;
  5. cin>>a;
  6. cout<<a+a%10*100+(a/10)%10*10+a/100;
  7. return 0;
  8. }

1021:Beginner's Guide] Finding Numbers II

Title Description

Find all integers in the range 1-500 that satisfy both division by 3 with remainder 2, division by 5 with remainder 3, and division by 7 with remainder 2.

importation

not have

exports

several

One per line

  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. for(int i=1;i<=500;i++){
  5. if(i%3==2&&i%5==3&&i%7==2){
  6. cout<<i<<" "<<endl;
  7. }
  8. }
  9. return 0;
  10. }

1022:[Getting Started] The Hundred Cents and Hundred Chickens Problem

Title Description

Buy 100 chickens, roosters, hens, and chicks for $100. The rooster costs 5 dollars a piece, the hen 3 dollars a piece, and the chicks 1 dollar 3 pieces. How many roosters, hens, and chicks should you buy?

importation

not have

exports

Each buy takes up one row and consists of 3 numbers in the order of the number of roosters, the number of hens, and the number of chicks. Each number is separated by a space.

  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. for(int i=1;i<=20;i++){
  5. for(int j=1;j<=33;j++){
  6. for(int k=1;k<=100;k++){
  7. if(i+j+k==100&&i*5+j*3+k/3.0==100){
  8. cout<<i<<" "<<j<<" "<<k<<endl;
  9. }
  10. }
  11. }
  12. }
  13. return 0;
  14. }

1025:[Getting Started] Coin Exchange

Title Description

A dollar bill is exchanged for 1, 2, and 5 cent coins, at least one of each, Q. How many ways are there to exchange them?

importation

not have

exports

The output is only one line (which means there is a carriage return symbol at the end) and consists of 1 integer.

  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. int sum=0;
  5. for(int i=1;i<=100;i++){
  6. for(int j=1;j<=50;j++){
  7. for(int k=1;k<=20;k++){
  8. if(i+j*2+k*5==100){
  9. sum++;
  10. }
  11. }
  12. }
  13. }
  14. cout<<sum;
  15. return 0;
  16. }

1027:Getting Started] Finding the sum of the digits of any three-digit number.

Title Description

For an arbitrary three-digit natural number X, program the sum S of the digits in each of its digits.

importation

Enter a line with only one integer x (100<=x<=999)

exports

The output is only one line and consists of 1 integer

Sample Input
123
Sample Output
6
  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. int x;
  5. cin>>x;
  6. cout<<x/100+x/10%10+x%100%10;
  7. return 0;
  8. }

1028:[Getting Started] Input a three-digit number and output it after matching the first and second digits.

Title Description

Input a three-digit natural number, then swap the hundredths digit of this number with the first digit, and output the swapped number

If a leading 0 exists after flip-flop, output leading 0 normally, e.g., 130, should output 031

importation

Enter a line with only one integer x (100<=x<=999).

exports

The output is only one line and consists of 1 integer.

Sample Input
123
Sample Output
321
  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. int x,a,b,c;
  5. cin>>x;
  6. a=x/100;
  7. b=x%100%10;
  8. c=x%100/10;
  9. cout<<b<<c<<a;
  10. return 0;
  11. }