2015 Zhejiang Province Blue Bridge Cup c/c++b Group personal solving

Source: Internet
Author: User
Tags ming

Number of Lotteries
Some people are superstitious figures, such as the number with "4", Think and "dead" homophonic, feel unlucky.
Although these statements are nonsense, they sometimes have to cater to the needs of the public. The lottery number for a sweepstakes is 5 digits (10000-99999), which requires that no number with "4" be present, and the organizer asks you to calculate how many tickets can be issued if any two tickets are not re-numbered.

52488


#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <  cctype> #include <vector> #include <cstdlib>using namespace std;/* run this program using the console Pauser Or add your own getch, System ("pause") or input loop */int main () {int i,j,ans=0,p,t,flag; for (i=10000;i<100000;i++) {t=i; flag=0;//?? 4 while (t!=0) {if (t%10==4) {flag=1;break;} t/=10;} if (flag==0) {ans++;//cout<<i<< "";}} cout<<ans<<endl; System ("pause"); return 0;}


Galaxy bomb

In the vast space of the X galaxy, many X-star man-made "bombs" were floated to serve as signposts in the universe.
Each bomb can be set to explode after a few days.
For example: The Alpha bomb was placed on January 1, 2015 and timed for 15 days, then it exploded on January 16, 2015.
There is a beta bomb, placed on November 9, 2014, timed for 1000 days, please calculate the exact date it exploded.


Please fill in the date in the format YYYY-MM-DD the 4-bit year 2-digit month 2-bit date. For example: 2015-02-19
Please write strictly in the format. No other text or symbols can appear.

2017-08-05

But I was wrong--

Three goats to offer Rui

Observe the following addition calculation:


The auspicious omen is shining
+ Three sheep offering Rui
-------------------
San Yang Sheng Bling


(See figure 1.jpg If you have alignment issues)


Among them, the same Chinese characters represent the same numbers, and the different Chinese characters represent different numbers.


Please fill in the 4-digit number (the answer is the only) represented by "San Yang Rui", do not fill in any superfluous content.


1085




In-grid output

The Stringingrid function prints the specified string in a grid of a specified size.
Requires the string to be centered in a horizontal, vertical, two direction.
If the string is too long, it is truncated.
If you can't just center it, you can do it slightly to the left or to a point.


The following program implements this logic, please fill in the missing code in the underlined section.


#include <stdio.h>
#include <string.h>


void Stringingrid (int width, int height, const char* s)
{
int i,k;
Char buf[1000];
strcpy (buf, s);
if (strlen (s) >width-2) buf[width-2]=0;

printf ("+");
for (i=0;i<width-2;i++) printf ("-");
printf ("+\n");

for (k=1; k< (height-1)/2;k++) {
printf ("|");
for (i=0;i<width-2;i++) printf ("");
printf ("|\n");
}

printf ("|");

printf ("%*s%s%*s", _____________________________________________); Blanks

printf ("|\n");

For (k= (height-1)/2+1; kprintf ("|");
for (i=0;i<width-2;i++) printf ("");
printf ("|\n");
}

printf ("+");
for (i=0;i<width-2;i++) printf ("-");
printf ("+\n");
}


int main ()
{
Stringingrid (20,6, "abcd1234");
return 0;
}


For the data in the topic, the output should be:
+------------------+
| |
| abcd1234 |
| |
| |
+------------------+




(See figure 1.jpg If there is an alignment problem)


Note: Fill in only what is missing, and do not write any existing code or descriptive text on any of the surfaces.


Buf[width-2]==0?0: (Width-2-strlen (s))/2,buf[width-2]==0? ":" ", Buf,buf[width-2]==0?0: (Width-1-strlen (s))/2,buf[ Width-2]==0? "": ""




Nine array Fractions

1,2,3...9 These nine numbers make up a fraction with a value of exactly 1/3, how does the group method work?


The following program implements this function, please fill in the missing code in the underlined section.


#include <stdio.h>


void Test (int x[])
{
int a = x[0]*1000 + x[1]*100 + x[2]*10 + x[3];
int b = x[4]*10000 + x[5]*1000 + x[6]*100 + x[7]*10 + x[8];

if (a*3==b) printf ("%d/%d\n", A, b);
}


void f (int x[], int k)
{
int i,t;
if (k>=9) {
Test (x);
Return
}

for (i=k; i<9; i++) {
{t=x[k]; x[k]=x[i]; x[i]=t;}
f (x,k+1);
_____________________________________________//Fill in the blanks
}
}

int main ()
{
int x[] = {1,2,3,4,5,6,7,8,9};
f (x,0);
return 0;
}




Note: Fill in only what is missing, and do not write any existing code or descriptive text on any of the surfaces.


{t=x[k]; x[k]=x[i]; x[i]=t;}




Addition variable multiplication

We all know: 1+2+3+ ... + 49 = 1225
You are now asked to turn two of these nonadjacent plus signs into multiplication sign, making the result 2015


Like what:
1+2+3+...+10*11+12+...+27*28+29+...+49 = 2015
Is the answer that meets the requirements.


Please look for another possible answer and submit the number to the left of the front multiplication sign (for example, commit 10).


Note: You are required to submit an integer, do not fill in any superfluous content.




-

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <  cctype> #include <vector> #include <cstdlib>using namespace std;/* run this program using the console Pauser Or add your own getch, System ("pause") or input loop */int main () {int i,j; for (i=1;i<46;i++) {(j=i+2;j<=49;j+ +) {int t=i* (i+1) +j* (j+1)-(i*2+2+j*2), if (t==790) cout<<i<< "" <<j<<endl;}   System ("pause"); return 0;}


Number of card types

Xiao Ming was hijacked to X Vegas and was forced to play cards with 3 other people.
A deck of poker (minus the size of ace, a total of 52), evenly distributed to 4 people, each 13 Zhang.
At this time, Xiao Ming's brain suddenly emerged a problem:
If you do not consider the suit, only consider the points, also do not consider the order of the cards you get, you can get the initial combination of the total number of types?


Please fill in this integer, do not fill in any superfluous content or descriptive text.
3598180

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <  cctype> #include <vector> #include <cstdlib>using namespace std;/* run this program using the console Pauser Or add your own getch, System ("pause") or input loop */int main () {int i[20]; long long ans=0; for (i[1]=0;i[1]<=4;i[1 ]++) for (i[2]=0;i[2]<=4;i[2]++) for (i[3]=0;i[3]<=4;i[3]++) for (i[4]=0;i[4]<=4;i[4]++) for (i[5]=0;i[5]< =4;i[5]++) for (i[6]=0;i[6]<=4;i[6]++) for (i[7]=0;i[7]<=4;i[7]++) for (i[8]=0;i[8]<=4;i[8]++) for (i[9]=0;i[ 9]<=4;i[9]++) for (i[10]=0;i[10]<=4;i[10]++) for (i[11]=0;i[11]<=4;i[11]++) for (i[12]=0;i[12]<=4;i[12]+ +) for (i[13]=0;i[13]<=4;i[13]++) {int t=0;for (int j=1;j<=13;j++) t+=i[j];if (t==13) ans++;}  cout<<ans<<endl; System ("pause"); return 0;}




Moving distance

The buildings of Planet X are all the same and arranged in a matrix style. The number of its buildings is ...
When a row is full, from the next line of the adjacent building to the opposite direction to automatic arranging.
For example: When the cell automatic arranging width is 6 o'clock, the situation begins as follows:


1 2 3 4 5 6
12 11 10 9 8 7
13 14 15 .....


Our problem is: Known two building numbers m and N, need to require the shortest moving distance between them (can not move diagonally direction)


Input is 3 integers w m n, spaces separated, all within 1 to 10000 range
W is automatic arranging width, m,n is the building number to be calculated.
An integer is required to indicate the shortest moving distance between two floors of M N.


For example:
User input:
6 8 2
Then, the program should output:
4


Again for example:
User input:
4 7 20
Then, the program should output:
5


Resource contract:
Peak memory Consumption < 256M
CPU Consumption < 1000ms




Please strictly according to the requirements of the output, do not use the superfluous printing similar: "Please enter ..." Redundant content.


All the code is placed in the same source file, after debugging passed, the copy is submitted to the source.


Note: The main function needs to return 0
Note: Use only ANSI c/ansi C + + standards, and do not invoke special functions that depend on the compilation environment or operating system.
Note: All dependent functions must explicitly #include <xxx&gt in the source file, and the common header files cannot be omitted from the project settings.


When committing, be careful to choose the type of compiler you expect.


#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cctype> #include <vector> #include <cstdlib> #include <cmath>using namespace Std;int map[10005][ 10005];int Main () {int i,j,w,m,n,t,mi,mj,ni,nj; while (cin>>w>>m>>n) {int cnt=1; if (m==n) {COUT<&L t;0<<endl; Continue } else if (m>n) t=m,m=n,n=t; for (i=0;i<100001;i++) {if (i%2) {for (j=w-1;j>=0;j--) {map[i][j]=cnt; if (cnt==m) {mi=i; mj=j;}  if (cnt==n) {ni=i; nj=j; goto flag;} cnt++; }} else {for  (j=0;j<w;j++) {map[i][j]=cnt; if (cnt==m) {mi=i; mj=j;}  if (cnt==n) {ni=i; nj=j; goto flag;} cnt++; }}}  Flag:cout<<abs (Mi-ni) +abs (MJ-NJ) <<endl;  } return 0;}


The last two questions are not all written.


2015 Zhejiang Province Blue Bridge Cup c/c++b Group personal solving

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.