3026 恶心的扑克

    xiaoxiao2021-03-25  130

    题目描述 Description

    有一副恶心的扑克,从小到大依次是3 , 4 , 5 , 6 , 7 , 8 , 9 , J , Q , K , A , 2 ,每种都有100张。现在输入一个string,每一个字符都是其中的一种,你的任务是:从小到大排序后输出。

    输入描述 Input Description

    参见样例

    输出描述 Output Description

    参见样例

    样例输入 Sample Input

     

    输入样例:4Q3KA292376J

     

    输出样例:334679JQKA22

    样例输出 Sample Output

    输出样例:334679JQKA22

    数据范围及提示 Data Size & Hint

    字符串长度小于200

    先排序,在统计KA2的个数,将字符串中的KA2删除,再将相应数目的KA2添加在字符串尾部

    #include<cstdio> #include<algorithm> #include<iostream> #include <string.h> #include<queue> using namespace std; int main() { char str[210],t[3]={0}; int len,i,j,k; cin>>str; len = strlen(str); sort(str,str+len); for (i=0; i<len; i++) { if (str[i]=='K'||str[i]=='A'||str[i]=='2') { if (str[i]=='K') t[0]++; if (str[i]=='A') t[1]++; if (str[i]=='2') t[2]++; for (j=i;j<len;j++) str[j] = str[j+1]; len--; i--; } } for (i=0; i<3; i++) for (j=0; j<t[i]; j++) { if (i==0) { str[len++] = 'K'; } else if (i==1) { str[len++] = 'A'; } else { str[len++] = '2'; } } str[len] = '\0'; cout<<str; return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-14745.html

    最新回复(0)