259 词
题目描述输入一个不多于5位的正整数,按逆序输出各位上的数字,末尾换行。 注意:确保输入的正整数的位数不多于5。 输入一个不多于5位的正整数。 输出逆序输出各位上的数字,中间以空格分隔。 注意末尾的换行。 #include<bits/stdc++.h>using namespace std;int main(){ int x,t; cin>>x; while(x!=0){ t=x; cout<<t%10<<” “; x=x/10; } return 0;}
1.6k 词
题目描述Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond. 输入In the first line, the number of cards n (n ≤ 52) is given. In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by ‘S’, ‘H’, ‘C’ and ‘D’ for s...
423 词
题目描述小明最近多位数加法运算学的很晕倒:(,幸好是做判断题,它只需要判断A+B最后一位数是否是C就可以了,可是他真的懒的厉害,这不让你写一个程序帮助他 输入两个长度不超过100位整数A B 一个个位数C 输出正确与否,正确是YES 错误则输出NO #include<bits/stdc++.h>using namespace std; int main(){ string a, b,a1,b1; int c,aa,bb; cin >> a >> b >> c; a1 = a[0]; b1 = b[0]; //取第一位 aa = atoi(a1.c_str()); //转换为整形 bb = atoi(b1.c_str()); if ((aa + bb)%10 == c)cout << “YES”; else cout <&l...
639 词
题目描述如果一个整数可以写成另一个整数的平方,则说它是一个完全平方数。比如$1,4,9,16$是完全平方数。输入一个整数,找到一个离它最近的完全平方数。 输入仅有一组测式数据,输入一个整数$N$($0≤N≤100000$)。 输出输出离它最近的完全平方数,如果$N$就是完全平方数,则输出$N$。 样例输入16 样例输出14 题解C++12345678910111213141516171819#include<iostream>using namespace std;int main() { int n, a = 1, b, c, nn; cin >> n; b = n; c = n; while (a * a != b) { while (a * a < b) {a++;} if (a * a != b) {a = 1;b--;} } while (a * a != c) { whil...
520 词
题目描述正整数的各位数字之和称为Tom数。求输入n, n≤231−1的Tom数! 输入每行一个整数n ,n≤231−1. 输出每行一个输出,对应该数的各位数之和. 方法一 #include<bits/stdc++.h>using namespace std;int main(){ int n; char s[1001]; while(scanf(“%s”,&s)!=EOF) { int a=0; n=strlen(s); for(int i=0; i<n; i++) { a+=(s[i]-‘0‘); } printf(“%d\n”,a); } return 0;} 方法二:优化版 #include<bits/stdc++.h>using namespace std;int main(){ char a[11]; while...
305 词
题目描述将一个长度为10的整型数组中的值按逆序重新存放。 如:原来的顺序为1,2,3,4,5,6,7,8,9,0,要求改为0,9,8,7,6,5,4,3,2,1 输入从键盘上输入以空格分隔的10个整数。 输出按相反的顺序输出这10个数,每个数占一行。 #include<bits/stdc++.h>using namespace std;int main(){ int a[10]; int i; for(i=0;i<10;i++){ scanf(“%d”,&a[i]); } for(i=9;i>=0;i–){ printf(“%d “,a[i]); } return 0;}
1.2k 词
题目描述扫雷是一个经典的游戏,在一个$N*M$区域中 输入一个$N*M$的雷区中的k个雷坐标,打印出所有雷区的分布 一个位置如果是雷则表示为*,否则应该是0~8,表示他周围八连通域中的地雷总数。 输入雷区尺寸:$3=<n,m<=20$地雷数目:$k<=M*N$和他们的坐标:$xi$,$yi$ 输出雷区的分布 每组后空一行  题解123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263#include<iostream>#include <cstring>using namespace std;const int maxn = 21;const int BOMB = 999;int a[maxn][maxn];int m, n, k, x, y;void show() { for (int i = 0; i < n...
990 词
题目描述数集拓展到实数范围内,仍有些运算无法进行。比如判别式小于0的一元二次方程仍无解,因此将数集再次扩充,达到复数范围。 定义:形如z=a+bi的数称为复数(complex number),其中规定i为虚数单位,且i^2=i*i=-1(a,b是任意实数) 我们将复数z=a+bi中的实数a称为复数z的实部(real part)记作Rez=a 实数b称为复数z的虚部(imaginary part)记作 Imz=b. 已知:当b=0时,z=a,这时复数成为实数; 当a=0且b≠0时 ,z=bi,我们就将其称为纯虚数。 定义: 对于复数z=a+bi,称复数z’=a-bi为z的共轭复数。 定义:将复数的实部与虚部的平方和的正的平方根的值称为该复数的模,记作∣z∣ 规定复数的乘法按照以下的法则进行: 设z1=a+bi,z2=c+di(a、b、c、d∈R)是任意两个复数,那么它们的积(a+bi)(c+di)=(ac-bd)+(bc+ad)i. ...
635 词
题目描述123457 3 8 8 1 02 7 4 44 5 2 6 5  图一表示一个5行的数字三角形。假设给定一个n行数字三角形,计算出从三角形顶至底的一条路径,使该路径经过的数字总和最大。 每一步只能由当前位置向下或向右下。 输入你的程序要能接受标准输入。第一行包含一个整数T,表示总的测试次数。 对于每一种情况:第一行包含一个整数N,其中1 < N < 100,表示三角形的行数。 接下来的N行输入表示三角形的每一行的元素Ai,j,其中0 < Ai,j < 100。 输出输出每次测试的最大值并且占一行。 题解1234567891011121314151617181920#include<iostream>using namespace std;int map[102][102], d[102][102];int main() { int T, n; cin >> T; while (T--) { cin >> n; for (int i = 1; i...
1.2k 词
题目描述You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room.For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that v persons left.Assume that initially no person lives in the building. 输入In the first line, the number of notices n is g...