题目描述
每个人都想成为大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;
}
总体感受:
这次题目也感觉不太难,就是需要知道题目所要求的是什么吧。