文章

7

粉丝

0

获赞

26

访问

1.5k

头像
字符串排序3 题解:OutPut Limit Exceeded 为啥?
P1261 北京大学机试题
发布于2025年3月7日 18:44
阅读数 196

#include<stdio.h>
#include<string.h>
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        char str[100][100];
        int num[n]; 
        int x=0; 

        getchar();

//fflush(stdin); 清空缓冲区,但好像容易出问题,最好还是getchar() 
        for(int i=0;i<n;i++)
        {
          fgets(str[i],101,stdin);
          int len =strlen(str[i]); 
          str[i][len-1]='\0'; //解决最后一个换行符不能与"stop"匹配的问题; 
          if(strcmp(str[i],"stop")==0)
          {
               break; 
          }
          x++; 
   ...

登录查看完整内容


登录后发布评论

2 条评论
ASDF807
2025年3月8日 12:21

//fflush(stdin); 清空缓冲区,但好像容易出问题,最好还是getchar() 

赞(0)
快乐小土狗
2025年3月7日 22:36

输入不要用while(1)死循环

改成

while(scanf("%d",&n)!=EOF)

赞(0)