
真心求解!!浙大ZOJ平台上3168题,觉得很简单啊,但一直WA。。。坐等哭求大牛!!
SortZOJ7-----------------------------------------------------------------------------...
Sort ZOJ7
--------------------------------------------------------------------------------
Time Limit: 1 Second Memory Limit: 32768 KB
--------------------------------------------------------------------------------
Given a string of no more than 1000 characters. You are supposed to sort the characters into a substring of all Z's followed by O's, J's, 7's, and the rest of the other characters.
Input
Each case gives a string described by the problem. The string given contains no space.
Output
For each test case, output the resulting string. Note the order of the characters other than Z, O, J and 7 must be kept after sorting.
Sample Input
t7ZJ7OhO7B7O7irZtOhZdayJ77
Sample Output
ZZZOOOOJJ7777777thBirthday
我的代码:
#include<iostream>
#include <cstring>
using namespace std;
int main(void)
{
int i,z=0,o=0,j=0,q=0,c=0;
char ss[1000]={0};
char buff[1000]={0};
cin>>ss;
for(i=0;i<strlen(ss);i++)
{
switch(ss[i])
{
case 'Z':z++;break;
case 'O':o++;break;
case 'J':j++;break;
case '7':q++;break;
default:buff[c++]=ss[i];
}
}
while(z--)
cout<<"Z";
while(o--)
cout<<"O";
while(j--)
cout<<"J";
while(q--)
cout<<"7";
for(i=0;i<c;i++)
cout<<buff[i];
//cout<<endl;
return 0;
} 展开
--------------------------------------------------------------------------------
Time Limit: 1 Second Memory Limit: 32768 KB
--------------------------------------------------------------------------------
Given a string of no more than 1000 characters. You are supposed to sort the characters into a substring of all Z's followed by O's, J's, 7's, and the rest of the other characters.
Input
Each case gives a string described by the problem. The string given contains no space.
Output
For each test case, output the resulting string. Note the order of the characters other than Z, O, J and 7 must be kept after sorting.
Sample Input
t7ZJ7OhO7B7O7irZtOhZdayJ77
Sample Output
ZZZOOOOJJ7777777thBirthday
我的代码:
#include<iostream>
#include <cstring>
using namespace std;
int main(void)
{
int i,z=0,o=0,j=0,q=0,c=0;
char ss[1000]={0};
char buff[1000]={0};
cin>>ss;
for(i=0;i<strlen(ss);i++)
{
switch(ss[i])
{
case 'Z':z++;break;
case 'O':o++;break;
case 'J':j++;break;
case '7':q++;break;
default:buff[c++]=ss[i];
}
}
while(z--)
cout<<"Z";
while(o--)
cout<<"O";
while(j--)
cout<<"J";
while(q--)
cout<<"7";
for(i=0;i<c;i++)
cout<<buff[i];
//cout<<endl;
return 0;
} 展开
展开全部
注意多组测试数据!
#include<iostream>
#include <cstring>
using namespace std;
int main()
{
char ss[1000]={0};
char buff[1000]={0};
while(cin>>ss)
{
int z=0,o=0,j=0,q=0,c=0;
for(int i=0;i<strlen(ss);i++)
{
switch(ss[i])
{
case 'Z':z++;break;
case 'O':o++;break;
case 'J':j++;break;
case '7':q++;break;
default:buff[c++]=ss[i];
}
}
while(z--)
cout<<"Z";
while(o--)
cout<<"O";
while(j--)
cout<<"J";
while(q--)
cout<<"7";
for(int i=0;i<c;i++)
cout<<buff[i];
cout<<endl;
}
return 0;
}
#include<iostream>
#include <cstring>
using namespace std;
int main()
{
char ss[1000]={0};
char buff[1000]={0};
while(cin>>ss)
{
int z=0,o=0,j=0,q=0,c=0;
for(int i=0;i<strlen(ss);i++)
{
switch(ss[i])
{
case 'Z':z++;break;
case 'O':o++;break;
case 'J':j++;break;
case '7':q++;break;
default:buff[c++]=ss[i];
}
}
while(z--)
cout<<"Z";
while(o--)
cout<<"O";
while(j--)
cout<<"J";
while(q--)
cout<<"7";
for(int i=0;i<c;i++)
cout<<buff[i];
cout<<endl;
}
return 0;
}
追问
可是这样不就一直在循环等待输入了吗?
追答
判题系统判断一到题目的程序正确与否的过程是这样的:
系统硬盘上保存这道题目的一个测试数据文件:
(我们叫这个文件 in.txt , 里面保存有:t7ZJ7OhO7B7O7irZtOhZdayJ77)
系统硬盘上保存这道题目的一个测试结果文件:
(我们叫这个文件 out.txt , 里面保存有:ZZZOOOOJJ7777777thBirthday)
测试的时候,把 in.txt 和 out.txt 文件读入到内存中。
a) 编译你提交的源代码,如果编译没通过,提示编译错误(compile error),停止判题。否则执行下一步。
b) 用 in.txt 的内容作为程序的输入(由 cin 读入),产生相应的输出到内存。【读入到文件末尾为止,这是 cin>>ss 返回 0】如果程序运行的过程中发生错认,比如超时(Time limit exceed),栈溢出(Runtime error)等,提示错误,停止判题。否则执行下一步。
c)程序产生相应的运行结果保存到内存,然后把这个运行结果和 out.txt 保存在内存中的内容逐一比较。如果有多余的空白字符(如空格,换行,Tab 键等),提示输出格式错误(presention error);如果有不一样的数据,提示答案错误(Wrong Answer)如果完全相同,则 Accept 。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询