題目描述
每個人都想成爲大V (VIP:Very Important Person),但要一點一點積累纔行,先從小v做起。要求輸出由小寫字母v組成的大V。
輸入描述:
無
輸出描述:
v v
v v
v
備註:
換行使用轉義字符‘\n’
AC代碼
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
//cout << "v v" << endl;
// cout << " v v" << endl;
//cout << " v" << endl;
printf("v v\n");
printf(" v v\n");
printf(" v\n");
return 0;
}
題目描述
BoBo教kiki學習C語言編程,先從經典的“屏幕顯示Hello, world!”開始,請輸出該功能對應的代碼。
輸入描述:
無
輸出描述:
輸出hello world
這題感覺怪怪的。。
貌似應該是輸出 printf(“Hello, world!\n”); 吧!
AC代碼
#include<stdio.h>
int main()
{
printf("printf(\"Hello, world!\\n\");");
return 0;
}
題目描述
確定不同整型數據類型在內存中佔多大(字節),輸出不同整型數據類型在內存中佔多大(字節)。
輸入描述:
無
輸出描述:
不同整型數據類型在內存中佔多大(字節),具體格式詳見輸出樣例,輸出樣例中的?爲不同整型數據類型在內存中佔的字節數。輸出樣例如下:
The size of short is ? bytes.
The size of int is ? bytes.
The size of long is ? bytes.
The size of long long is ? bytes.
AC代碼
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
cout<<"The size of short is "<<sizeof(short)<<" bytes."<<endl;
cout<<"The size of int is "<<sizeof(int)<<" bytes."<<endl;
cout<<"The size of long is "<<sizeof(long)<<" bytes."<<endl;
cout<<"The size of long long is "<<sizeof(long long)<<" bytes."<<endl;
return 0;
}
題目描述
據說智商140以上者稱爲天才,KiKi想知道他自己是不是天才,請幫他編程判斷。輸入一個整數表示一個人的智商,如果大於等於140,則表明他是一個天才,輸出“Genius”。
輸入描述:
多組輸入,每行輸入包括一個整數表示的智商。
輸出描述:
針對每行輸入,輸出“Genius”。
示例1
輸入
160
輸出
Genius
AC代碼
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
int zhi;
while (cin>>zhi) {
if (zhi >= 140) {
cout<<"Genius"<<endl;
}
}
return 0;
}
題目描述
從鍵盤任意輸入一個字符,編程判斷是否是字母(包括大小寫)。
輸入描述:
多組輸入,每行輸入包括一個字符。
輸出描述:
針對每行輸入,輸出該字符是字母(YES)或不是(NO)。
示例1
輸入
H 9
輸出
YES NO
AC代碼
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
char c;
while (cin >> c) {
if (c >= 'a' && c<= 'z' || c >= 'A' && c<= 'Z') {
cout<<"YES"<<endl;
} else {
cout<<"NO"<<endl;
}
}
return 0;
}
題目描述
KiKi學習了循環,BoBo老師給他出了一系列打印圖案的練習,該任務是打印用“*”組成的菱形圖案。
輸入描述:
多組輸入,一個整數(2~20)。
輸出描述:
針對每行輸入,輸出用“*”組成的菱形,每個“*”後面有一個空格。
示例1
輸入
2
輸出
*
* *
* * *
* *
*
示例2
輸入
3
輸出
*
* *
* * *
* * * *
* * *
* *
*
示例3
輸入
4
輸出
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
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 cnt = 1;
int space = n;
for(int i=0;i<n;i++)
{
for(int k=0;k<space;k++)
cout<<" ";
for(int j=0;j<cnt;j++)
{
cout<<"* ";
}
cout<<endl;
cnt += 1;
space--;
}
for(int i=0;i<cnt;i++)
cout<<"* ";
cout<<endl;
cnt -= 1;
space++;
for(int i=0;i<n;i++)
{
for(int k=0;k<space;k++)
cout<<" ";
for(int j=0;j<cnt;j++)
{
cout<<"* ";
}
cout<<endl;
cnt -= 1;
space++;
}
}
return 0;
}
題目描述
有個軟件系統登錄的用戶名和密碼爲(用戶名:admin,密碼:admin),用戶輸入用戶名和密碼,判斷是否登錄成功。
輸入描述:
多組測試數據,每行有兩個用空格分開的字符串,第一個爲用戶名,第二個位密碼。
輸出描述:
針對每組輸入測試數據,輸出爲一行,一個字符串(“Login Success!”或“Login Fail!”)。
示例1
輸入
admin admin
輸出
Login Success!
示例2
輸入
admin abc
輸出
Login Fail!
AC代碼
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
string user, pass;
while (cin >> user >> pass) {
if (user == "admin" && pass == "admin") {
cout<<"Login Success!"<<endl;
} else {
cout<<"Login Fail!"<<endl;
}
}
return 0;
}
題目描述
輸入兩個升序排列的序列,將兩個序列合併爲一個有序序列並輸出。
輸入描述:
輸入包含三行,
第一行包含兩個正整數n, m(1 ≤ n,m ≤ 100),用空格分隔。n表示第二行第一個升序序列中數字的個數,m表示第三行第二個升序序列中數字的個數。
第二行包含n個整數(範圍1~5000),用空格分隔。
第三行包含m個整數(範圍1~5000),用空格分隔。
輸出描述:
輸出爲一行,輸出長度爲n+m的升序序列,即長度爲n的升序序列和長度爲m的升序序列中的元素重新進行升序序列排列合併。
示例1
輸入
5 6
1 3 7 9 22
2 8 10 17 33 44
輸出
1 2 3 7 8 9 10 17 22 33 44
AC代碼
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int he = n + m;
int a[he];
for(int i=0;i<he;i++)
{
cin>>a[i];
}
sort(a,a+he);
for(int i=0;i<he;i++)
{
cout<<a[i]<<" ";
}
return 0;
}
題目描述
KiKi有一個矩陣,他想知道經過k次行變換或列變換後得到的矩陣。請編程幫他解答。
輸入描述:
第一行包含兩個整數n和m,表示一個矩陣包含n行m列,用空格分隔。 (1≤n≤10,1≤m≤10)
從2到n+1行,每行輸入m個整數(範圍-231~231-1),用空格分隔,共輸入n*m個數,表示第一個矩陣中的元素。
接下來一行輸入k,表示要執行k次操作(1≤k≤5)。接下來有k行,每行包括一個字符t和兩個數a和b,中間用空格格分隔,t代表需要執行的操作,當t爲字符'r'時代表進行行變換,當t爲字符'c'時代表進行列變換,a和b爲需要互換的行或列(1≤a≤b≤n≤10,1≤a≤b≤m≤10)。
輸出描述:
輸出n行m列,爲矩陣交換後的結果。每個數後面有一個空格。
示例1
輸入
2 2
1 2
3 4
1
r 1 2
輸出
3 4
1 2
AC代碼
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define endl '\n'
int main()
{
int n,m;
cin>>n>>m;
int nums[n][m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>nums[i][j];
}
}
char t;
int k,a,b;
cin>>k;
for(int l=0;l<k;l++)
{
cin>>t>>a>>b;
if (t == 'r') {
for(int i=0;i<m;i++)
{
int temp = nums[a-1][i];
nums[a-1][i] = nums[b-1][i];
nums[b-1][i] = temp;
}
}else if (t == 'c') {
for(int i=0;i<n;i++)
{
int temp = nums[i][a-1];
nums[i][a-1] = nums[i][b-1];
nums[i][b-1] = temp;
}
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cout<<nums[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
題目描述
KiKi和BoBo玩 “井”字棋。也就是在九宮格中,只要任意行、列,或者任意對角線上面出現三個連續相同的棋子,就能獲勝。請根據棋盤狀態,判斷當前輸贏。
輸入描述:
三行三列的字符元素,代表棋盤狀態,字符元素用空格分開,代表當前棋盤,其中元素爲K代表KiKi玩家的棋子,爲O表示沒有棋子,爲B代表BoBo玩家的棋子。
輸出描述:
如果KiKi獲勝,輸出“KiKi wins!”;
如果BoBo獲勝,輸出“BoBo wins!”;
如果沒有獲勝,輸出“No winner!”。
示例1
輸入
K O B
O K B
B O K
輸出
KiKi wins!
AC代碼
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;
const int N = 3;
char a[3][3];
bool checkWiner(char c) {
int cnt = 0;
//檢查 (0,0)->(2,2) 是否滿足要求
for(int i=0;i<N;i++)
{
if (a[i][i] == c) {
cnt++;
}
}
if (cnt == 3) return true;
cnt = 0;
//檢查 (0,2)->(2,0) 是否滿足要求
if (a[0][2] == c && a[1][1] == c && a[2][0] == c) {
return true;
}
//三行檢查一遍
for(int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
{
if (a[i][j] == c) {
cnt++;
}
}
if (cnt == 3) return true;
cnt = 0;
}
//三列檢查一遍
for(int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
{
if (a[j][i] == c) {
cnt++;
}
}
if (cnt == 3) return true;
cnt = 0;
}
return false;
}
int main()
{
for(int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
{
cin>>a[i][j];
}
}
bool winK = 0, winB = 0;
winK = checkWiner('K');
winB = checkWiner('B');
if (winK && winB) {
cout<<"No winner!";
}
else if (winK) {
cout<<"KiKi wins!";
}
else if (winB) {
cout<<"BoBo wins!";
} else {
cout<<"No winner!";
}
return 0;
}
總體感受:
這次題目也感覺不太難,就是需要知道題目所要求的是什麼吧。