读懂题目之后自然离不开打表,哈哈哈
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin>>n) {
if (n == 1) {
cout << "c 0 c 4 c 8 c 12 d 3 d 7 d 11 h 2 h 6 h 10 s 1 s 5 s 9"<<endl;
} else if (n == 2) {
cout << "c 1 c 5 c 9 d 0 d 4 d 8 d 12 h 3 h 7 h 11 s 2 s 6 s 10"<<endl;
} else if (n == 3) {
cout << "c 2 c 6 c 10 d 1 d 5 d 9 h 0 h 4 h 8 h 12 s 3 s 7 s 11"<<endl;
} else {
cout << "c 3 c 7 c 11 d 2 d 6 d 10 h 1 h 5 h 9 s 0 s 4 s 8 s 12"<<endl;
}
}
}
总结规律也不是不可以
#include <bits/stdc++.h>
using namespace std;
int main() {
int i = 0;// 统计已发的牌张数
int num = 0;// 当前牌的数字
int count = 0;// 统计换花色的次数
int perNum = 0;// 人员编号
char a[6] = "cdhsc";
char ch = a[count];// 当前牌的花色
while (scanf("%d", &perNum) != EOF) {
// 重置数据
i = 0;
num = perNum - 1;
count = 0;
ch = a[count];
printf("c %d", num);
i++;
while (i < 13) {
num += 4;
if (num > 12) {
num %= 13;
ch = a[++count];// 换花色
printf(" %c %d", ch, num);
}
else {
printf(" %c %d", ch, num);
}
i++;
}
printf("\n");
}
return 0;
}
C:\Users\10715\Desktop\未命??.cpp [Error] initializer-string for array of chars is too long [-fpermissive]
解决办法:字符数组初始化时,数组大小一定要大于字符串长度+1,否则编译错误。
字符串数组最后有\0。
#include <iostream>
#include <algorithm>
using namespace std;
int R;
int D[1000][1000];
int Maxsum(int i,int j){
if(i==R)
return D[i][j];
int x=Maxsum(i+1,j);
int y=Maxsum(i+1,j+1);
return max(x,y)+D[i][j];
}
int main(){
while(scanf("%d",&R)!=EOF){
for(int i=1;i<=R;i++)
for(int j=1;j<=i;j++)
scanf("%d",&D[i][j]);
cout<<Maxsum(1,1)<<endl;
}
return 0;
}
明明的问题可以归结为:试编程将一个稀疏矩阵a转换成只存放非零元素的矩阵b,即找出每个不是0的元素,按从左到右从上到下的顺序,输出其所在的行和列以及它的值。
#include <bits/stdc++.h>
using namespace std;
int main() {
int m = 0, n = 0;
int a[100][100] = {
0};
int i = 0, j = 0;
while (cin>>m>>n) {
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
cin>>a[i][j];
}
}
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
if (a[i][j] != 0) {
printf("%d %d %d\n", i + 1, j + 1, a[i][j]);
}
}
}cout<<endl;
}
}
明明的问题可以归结为:有一个r×r的矩阵,把矩阵中的数以左上到右下的对角线的方式进行转换,然后输出转换后的矩阵。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
int i,j;
while(~scanf("%d",&n))
{
int a[10][10];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(j<n-1)
printf("%d ",a[j][i]);
else
printf("%d\n",a[j][i]);
}
printf("\n");
}
return 0;
}
#include<stdio.h>
#include<string.h>
#define MAX_SIZE 21
int main() {
int n = 0;
int count = 0;
int i = 0, j = 0;
int preRow = 0, preCol = 0;// 前一个数所在行和列
<