Vjudge
2017-07-1607:31:35
writer:pprp
題目介紹:很基礎的string用法
題目如下:
讀入一個字符串,字符串中包含ZOJ三個字符,個數不一定相等,按ZOJ的順序輸出,當某個字符用完時,剩下的仍然按照ZOJ的順序輸出。
Input題目包含多組用例,每組用例占一行,包含ZOJ三個字符,當輸入“E”時表示輸入結束。
1<=length<=100。
Output對于每組輸入,請輸出一行,表示按照要求處理后的字符串。
具體可見樣例。Sample Input
ZZOOOJJJ ZZZZOOOOOJJJ ZOOOJJ E
Sample Output
ZOJZOJOJ ZOJZOJZOJZOO ZOJOJO
代碼如下:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
while(cin >> str&&str[0]!='E')
{
int cntz = 0;
int cnto = 0;
int cntj = 0;
for(size_t i = 0 ; i < str.length() ;i++)
{
if(str[i] == 'Z')
{
cntz++;
}
else if(str[i] == 'O')
{
cnto++;
}
else
{
cntj++;
}
}
for(size_t i = 0 ; i < str.length();i++)
{
if(cntz-->0)
{
cout <<"Z";
}
if(cnto-->0)
{
cout <<"O";
}
if(cntj-->0)
{
cout <<"J";
}
}
cout << endl;
}
return 0;
}
運行結果:Accepted
總結
- 上一篇: jsp文件上传_猿蜕变系列7——也说说s
- 下一篇: 用于安装python第三方库的工具是_P