DHU OJ 二维数组 发牌

 思路及代码

//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)

菜菜,不是教程,做题和学习记录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值