獎券數目
有些人很迷信數字,比如帶“4”的數字,認爲和“死”諧音,就覺得不吉利。
雖然這些說法純屬無稽之談,但有時還要迎合大衆的需求。某抽獎活動的獎券號碼是5位數(10000-99999),要求其中不要出現帶“4”的號碼,主辦單位請你計算一下,如果任何兩張獎券不重號,最多可發出獎券多少張。
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;
}
星系炸彈
在X星系的廣袤空間中漂浮着許多X星人造“炸彈”,用來作爲宇宙中的路標。
每個炸彈都可以設定多少天之後爆炸。
比如:阿爾法炸彈2015年1月1日放置,定時爲15天,則它在2015年1月16日爆炸。
有一個貝塔炸彈,2014年11月9日放置,定時爲1000天,請你計算它爆炸的準確日期。
請填寫該日期,格式爲 yyyy-mm-dd 即4位年份2位月份2位日期。比如:2015-02-19
請嚴格按照格式書寫。不能出現其它文字或符號。
2017-08-05
可惜我算錯了- -
三羊獻瑞
觀察下面的加法算式:
祥 瑞 生 輝
+ 三 羊 獻 瑞
-------------------
三 羊 生 瑞 氣
(如果有對齊問題,可以參看【圖1.jpg】)
其中,相同的漢字代表相同的數字,不同的漢字代表不同的數字。
請你填寫“三羊獻瑞”所代表的4位數字(答案唯一),不要填寫任何多餘內容。
1085
格子中輸出
StringInGrid函數會在一個指定大小的格子中打印指定的字符串。
要求字符串在水平、垂直兩個方向上都居中。
如果字符串太長,就截斷。
如果不能恰好居中,可以稍稍偏左或者偏上一點。
下面的程序實現這個邏輯,請填寫劃線部分缺少的代碼。
#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",_____________________________________________); //填空
printf("|\n");
for(k=(height-1)/2+1; k<height-1; k++){
printf("|");
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;
}
對於題目中數據,應該輸出:
+------------------+
| |
| abcd1234 |
| |
| |
+------------------+
(如果出現對齊問題,參看【圖1.jpg】)
注意:只填寫缺少的內容,不要書寫任何題面已有代碼或說明性文字。
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?"":" "
九數組分數
1,2,3...9 這九個數字組成一個分數,其值恰好爲1/3,如何組法?
下面的程序實現了該功能,請填寫劃線部分缺失的代碼。
#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);
_____________________________________________ // 填空處
}
}
int main()
{
int x[] = {1,2,3,4,5,6,7,8,9};
f(x,0);
return 0;
}
注意:只填寫缺少的內容,不要書寫任何題面已有代碼或說明性文字。
{t=x[k]; x[k]=x[i]; x[i]=t;}
加法變乘法
我們都知道:1+2+3+ ... + 49 = 1225
現在要求你把其中兩個不相鄰的加號變成乘號,使得結果爲2015
比如:
1+2+3+...+10*11+12+...+27*28+29+...+49 = 2015
就是符合要求的答案。
請你尋找另外一個可能的答案,並把位置靠前的那個乘號左邊的數字提交(對於示例,就是提交10)。
注意:需要你提交的是一個整數,不要填寫任何多餘的內容。
16
#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++)
{
for(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;
}
牌型種數
小明被劫持到X賭城,被迫與其他3人玩牌。
一副撲克牌(去掉大小王牌,共52張),均勻發給4個人,每個人13張。
這時,小明腦子裏突然冒出一個問題:
如果不考慮花色,只考慮點數,也不考慮自己得到的牌的先後順序,自己手裏能拿到的初始牌型組合一共有多少種呢?
請填寫該整數,不要填寫任何多餘的內容或說明文字。
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;
}
移動距離
X星球居民小區的樓房全是一樣的,並且按矩陣樣式排列。其樓房的編號爲1,2,3...
當排滿一行時,從下一行相鄰的樓往反方向排號。
比如:當小區排號寬度爲6時,開始情形如下:
1 2 3 4 5 6
12 11 10 9 8 7
13 14 15 .....
我們的問題是:已知了兩個樓號m和n,需要求出它們之間的最短移動距離(不能斜線方向移動)
輸入爲3個整數w m n,空格分開,都在1到10000範圍內
w爲排號寬度,m,n爲待計算的樓號。
要求輸出一個整數,表示m n 兩樓間最短移動距離。
例如:
用戶輸入:
6 8 2
則,程序應該輸出:
4
再例如:
用戶輸入:
4 7 20
則,程序應該輸出:
5
資源約定:
峯值內存消耗 < 256M
CPU消耗 < 1000ms
請嚴格按要求輸出,不要畫蛇添足地打印類似:“請您輸入...” 的多餘內容。
所有代碼放在同一個源文件中,調試通過後,拷貝提交該源碼。
注意: main函數需要返回0
注意: 只使用ANSI C/ANSI C++ 標準,不要調用依賴於編譯環境或操作系統的特殊函數。
注意: 所有依賴的函數必須明確地在源文件中 #include <xxx>, 不能通過工程設置而省略常用頭文件。
提交時,注意選擇所期望的編譯器類型。
#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<<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;
}
最後兩題麼沒有全寫。