A.ASCII碼
題目描述
BoBo教KiKi字符常量或字符變量表示的字符在內存中以ASCII碼形式存儲。BoBo出了一個問題給KiKi,轉換以下ASCII碼爲對應字符並輸出他們。
73, 32, 99, 97, 110, 32, 100, 111, 32, 105, 116 , 33
輸入描述:
無
輸出描述:
轉換輸出題目中給出的所有ASCII到對應的字符。 AC代碼
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
printf("%c%c%c%c%c%c%c%c%c%c%c%c",73,32,99,97,110,32,100,111,32,105,116,33);
return 0;
}
B.你能活多少秒
題目描述
問題:一年約有3.156×107s,要求輸入您的年齡,顯示該年齡合多少秒。
輸入描述:
一行,包括一個整數age(0<age<=200)。
輸出描述:
一行,包含一個整數,輸出年齡對應的秒數。
示例1
輸入
20
輸出
631200000
AC代碼
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
int age;
cin>>age;
cout<<(long long)3.156e7 * age;
return 0;
}
C.2的n次方計算
題目描述
不使用累計乘法的基礎上,通過移位運算(<<)實現2的n次方的計算。
輸入描述:
多組輸入,每一行輸入整數n(0 <= n < 31)。
輸出描述:
針對每組輸入輸出對應的2的n次方的結果。
示例1
輸入
2 10
輸出
4 1024
AC代碼
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
int n;
while(cin>>n) {
int sum = 1;
for(int i=0;i<n;i++)
{
sum = sum<<1;
}
cout<<sum<<endl;
}
return 0;
}
D.及格分數
題目描述
KiKi想知道他的考試分數是否通過,請幫他判斷。從鍵盤任意輸入一個整數表示的分數,編程判斷該分數是否在及格範圍內,如果及格,即:分數大於等於60分,是輸出“Pass”,否則,輸出“Fail”。
輸入描述:
多組輸入,每行輸入包括一個整數表示的分數(0~100)。
輸出描述:
針對每行輸入,輸出“Pass”或“Fail”。
示例1
輸入
94
輸出
Pass
示例2
輸入
44
輸出
Fail
AC代碼
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
int s;
cin>>s;
if(s>=60) {
cout<<"Pass";
} else {
cout<<"Fail";
}
return 0;
}
鏈接:https://ac.nowcoder.com/acm/contest/5904/E
來源:牛客網
題目描述
KiKi想知道從鍵盤輸入的兩個數的大小關係,請編程實現。
輸入描述:
題目有多組輸入數據,每一行輸入兩個整數(範圍(1 ~231-1),用空格分隔。
輸出描述:
針對每行輸入,輸出兩個整數及其大小關係,數字和關係運算符之間沒有空格,詳見輸入輸出樣例。
示例1
輸入
1 1
輸出
1=1
示例2
輸入
1 0
1 0
輸出
1>0
示例3
輸入
0 1
輸出
0<1
AC代碼
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
int a,b;
while(cin>>a>>b) {
cout<<a;
if(a==b) {
cout<<"=";
}else if(a>b){
cout<<">";
}else{
cout<<"<";
}
cout<<b<<endl;
}
return 0;
}
題目描述
BMI指數(即身體質量指數)是用體重公斤數除以身高米數平方得出的數字,是目前國際上常用的衡量人體胖瘦程度以及是否健康的一個標準。例如:一個人的身高爲1.75米,體重爲68千克,他的BMI=68/(1.75^2)=22.2(千克/米^2)。當BMI指數爲18.5~23.9時屬正常,否則表示身體存在健康風險。編程判斷人體健康情況。
輸入描述:
一行,輸入一個人的體重(千克)和身高(米),中間用一個空格分隔。
輸出描述:
一行,輸出身體Normal(正常)或Abnormal(不正常)。
示例1
輸入
68 1.75
輸出
Normal
示例2
輸入
67.5 1.65
輸出
Abnormal
AC代碼
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
double w, h;
while(cin>>w>>h){
double BMI = w/(h*h);
if(BMI<18.5 || BMI>23.9) {
cout<<"Abnormal";
}else{
cout<<"Normal";
}
cout<<endl;
}
return 0;
}
題目描述
KiKi學習了循環,BoBo老師給他出了一系列打印圖案的練習,該任務是打印用“*”組成的翻轉直角三角形圖案。
輸入描述:
多組輸入,一個整數(2~20),表示翻轉直角三角形直角邊的長度,即“*”的數量,也表示輸出行數。
輸出描述:
針對每行輸入,輸出用“*”組成的對應長度的翻轉直角三角形,每個“*”後面有一個空格。
示例1
輸入
5
輸出
* * * * * * * * * * * * * * *
示例2
輸入
6
輸出
* * * * * * * * * * * * * * * * * * * * *
AC代碼
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
int len;
while(cin>>len) {
for(int i=0;i<len;i++)
{
for(int j=i;j<len;j++)
{
cout<<"* ";
}
cout<<endl;
}
}
return 0;
}
題目描述
輸入10個整數,分別統計輸出正數、負數的個數。
輸入描述:
輸入10個整數(範圍-231~231-1),用空格分隔。
輸出描述:
兩行,第一行正數個數,第二行負數個數,具體格式見樣例。
示例1
輸入
-1 2 3 -6 7 8 -1 6 8 10
輸出
positive:7 negative:3 AC代碼
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;
const int N = 10;
int main()
{
int i=0, tmp, zheng=0, fu=0;
while(++i<=N && cin>>tmp) {
if(tmp>=0) zheng++;
else fu++;
}
cout<<"positive:"<<zheng<<endl;
cout<<"negative:"<<fu;
return 0;
}
題目描述
KiKi得到了兩個n行m列的矩陣,他想知道兩個矩陣是否相等,請你回答他。(當兩個矩陣對應數組元素都相等時兩個矩陣相等)。
輸入描述:
第一行包含兩個整數n和m,表示兩個矩陣包含n行m列,用空格分隔。
從2到n+1行,每行輸入m個整數(範圍-231~231-1),用空格分隔,共輸入n*m個數,表示第一個矩陣中的元素。
從n+2行到2n+1,每行輸入m個整數(範圍-231~231-1),用空格分隔,共輸入n*m個數,表示第二個矩陣中的元素。
1 < n,m < 10
輸出描述:
一行,如果兩個矩陣相等輸出"Yes"並換行,否則輸出"No"並換行。
示例1
輸入
2 2 1 2 3 4 1 2 3 4
輸出
Yes
AC代碼
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
int n, m, flag=1, temp;
cin>>n>>m;
int A[n][m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>A[i][j];
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>temp;
if(temp != A[i][j]) {
flag = 0;
goto end; //跳出多重循環
}
}
}
end:
if(flag) {
cout<<"Yes"<<endl;
} else {
cout<<"No"<<endl;
}
return 0;
}
感想
感覺本練習賽的題目還是很基礎的。