思路及代码
//input 多组n int 1<= <= 4
#include<iostream>
using namespace std;
int main(){
int n;
//solution
//calculate people n 牌
string list[52] = {"c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c12",
"d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "d10", "d11", "d12",
"h0", "h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8", "h9", "h10", "h11", "h12",
"s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11", "s12"};
string ans[4][13];
for (int i = 0; i <= 51; i++){
switch(i%4){
case 0:
ans[0][i/4] = list[i];
case 1:
ans[1][i/4] = list[i];
case 2:
ans[2][i/4] = list[i];
case 3:
ans[3][i/4] = list[i];
}
}
//output people n 牌
while (cin >> n){
for (int j = 0;j <= 11; j++){
string str = ans[n-1][j];
cout << str[0] << ' ' << str.substr(1,str.length()-1) << ' ';
}
string last_str = ans[n-1][12];
cout << last_str[0] << ' ' << last_str.substr(1,last_str.length()-1) << endl;
}
return 0;
}
参考:1️⃣ C++中string类,取后几位字符_string截取后几位-CSDN博客
收获:1️⃣string取子字符串 substr(start, length)
菜菜,不是教程,做题和学习记录