天梯赛 L1-023 输出GPLT (20 分)
生活随笔
收集整理的這篇文章主要介紹了
天梯赛 L1-023 输出GPLT (20 分)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
首先統(tǒng)計個數(shù),再一輪輪輸出
#include <iostream> using namespace std;int main() {ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);int cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;string s; cin >> s;for (int i = 0; i < s.size(); i ++ ){s[i] = toupper(s[i]);if (s[i] == 'G') cnt1 ++ ;if (s[i] == 'P') cnt2 ++ ;if (s[i] == 'L') cnt3 ++ ;if (s[i] == 'T') cnt4 ++ ;}while (1){bool ok = false;if (cnt1){cout << 'G';ok = true;cnt1 -- ;}if (cnt2){cout << 'P';ok = true;cnt2 -- ;}if (cnt3){cout << 'L';ok = true;cnt3 -- ;}if (cnt4){cout << 'T';ok = true;cnt4 -- ;}if (!ok) break;} }總結(jié)
以上是生活随笔為你收集整理的天梯赛 L1-023 输出GPLT (20 分)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 天梯赛 L1-009 N个数求和 (20
- 下一篇: 天梯赛 L1-025 正整数A+B (1