zoukankan      html  css  js  c++  java
  • 训练赛bug总结

    先说最后出的模拟题 RE一发 因为没去掉freopen

     1 #include<cstdio>
     2 #include<map>
     3 #include<iostream>
     4 #include<string>
     5 #define debug(a) cerr<<#a<<"=="<<a<<endl
     6 using namespace std;
     7 
     8 map<pair<string,string>,bool>mp;
     9 map<pair<string,string>,bool>vis;
    10 
    11 char s[1005];
    12 
    13 int main()
    14 {
    15     mp.clear(),vis.clear();
    16     string str;
    17 ///    一定要把freopen去掉
    18 ///    freopen("in.txt","r",stdin);
    19     while(gets(s))
    20     {
    21         int i=0;
    22         string name1,name2;
    23         for(;s[i]!='-';i++)
    24             name1+=s[i];
    25         i+=2;
    26         for(;s[i]!=':';i++)
    27             name2+=s[i];
    28 //        debug(name1),debug(name2);
    29         i++;
    30         bool l=false;
    31         while(s[i])
    32         {
    33             bool ok=true;
    34             string tmp("");
    35             for(;s[i]>='a'&&s[i]<='z' ||s[i]>='A'&&s[i]<='Z' ;i++)
    36                 if(s[i]>='A'&&s[i]<='Z')tmp+=s[i]+32;
    37                 else tmp+=s[i];
    38             if(tmp.find("hehe")!=-1)
    39             {
    40                 int len=tmp.size();
    41                 for(int j=0;j<len;j++)
    42                 {
    43                     if(j%2==1 && tmp[j]!='e') ok=false;
    44                     if(j%2==0 && tmp[j]!='h') ok=false;
    45                 }
    46             }
    47             else ok=false;
    48             if(ok) {l=true;break;}
    49             i++;
    50         }
    51         if(name1>name2) swap(name1,name2);
    52         pair<string,string> tmp;
    53         tmp=make_pair(name1,name2);
    54         mp[tmp]=l;
    55 //        debug(l);
    56     }
    57     double ans=0;
    58     map<pair<string,string>,bool>::iterator iter=mp.begin();
    59     for(; iter!=mp.end(); iter++)
    60     {
    61         if( iter->second == true) ans+=1.0;
    62     }
    63 //    debug(ans);
    64     ans=((1.0*ans/mp.size())*100);
    65     printf("%.0f%%
    ",ans);
    66     return 0;
    67 }/*
    68 
    69 A->B: Hello!
    70 A->C: Hi!
    71 B->A: Hehe
    72 B->D: Hei!
    73 D->B: How are you?
    74 A->C: Hi???
    75 A->C: Are you there?
    76 B->D: Hehehei!
    77 D->B: What does hehehei mean?
    78 F->E: I want to hehehehehe yah.
    79 
    80 */

    然后说最先出的水题 没打case 老毛病= =

     1 #include<cstdio>
     2 
     3 const int maxn=1e5+10;
     4 
     5 long long num[maxn];
     6 int tot;
     7 
     8 void init()
     9 {
    10     int i=0;
    11     while(i*i<maxn)
    12     {
    13         num[i]=0;
    14         num[i]=1ll*i*i;
    15         i++;
    16     }
    17     tot=i;
    18 }
    19 
    20 int main()
    21 {
    22     ///别忘了打case
    23     int T,cas=1;
    24     scanf("%d",&T);
    25     init();
    26     while(T--)
    27     {
    28         int ans=0;
    29         char str[5];
    30         scanf("%s",str);
    31         int a[5];
    32         a[0]=str[0]-'0',a[1]=str[1]-'0',a[2]=str[2]-'0',a[3]=str[3]-'0';
    33 //        printf("%d %d %d %d
    ",a[0],a[1],a[2],a[3]);
    34         for(int i=1;i<=9;i++)
    35         {
    36             if(a[0]==i) continue;
    37             int number=i*1000+a[1]*100+a[2]*10+a[3];
    38 //            printf("%d
    ",number);
    39             for(int i=0;i<tot;i++)
    40             {
    41                 if(num[i]==number) ans++;
    42             }
    43         }
    44         for(int i=0;i<=9;i++)
    45         {
    46             if(a[1]==i) continue;
    47             int number=a[0]*1000+i*100+a[2]*10+a[3];
    48 
    49             for(int i=0;i<tot;i++)
    50             {
    51                 if(num[i]==number) ans++;
    52             }
    53         }
    54         for(int i=0;i<=9;i++)
    55         {
    56             if(a[2]==i) continue;
    57             int number=a[0]*1000+a[1]*100+i*10+a[3];
    58             for(int i=0;i<tot;i++)
    59             {
    60                 if(num[i]==number) ans++;
    61             }
    62         }
    63         for(int i=0;i<=9;i++)
    64         {
    65             if(a[3]==i) continue;
    66             int number=a[0]*1000+a[1]*100+a[2]*10+i;
    67             for(int i=0;i<tot;i++)
    68             {
    69                 if(num[i]==number) ans++;
    70             }
    71         }
    72         ///别忘了打case!
    73         printf("Case %d: %d
    ",cas++,ans);
    74     }
    75     return 0;
    76 }/*
    77 
    78 2
    79 7844
    80 9121
    81 
    82 */

    然后就是代码不严谨的问题 已经判断出结果了 就不用走接下来的循环了 注意设计极端样例

     1 #include<cstdio>
     2 #include<cstring>
     3 
     4 const int maxn=1e5+10;
     5 
     6 long long num[maxn];
     7 int tot;
     8 
     9 char str[105],str1[105];
    10 
    11 int main()
    12 {
    13     int T,cas=1;
    14     while(~scanf("%s",str))
    15     {
    16         printf("Case %d: ",cas++);
    17         scanf("%s",str1);
    18         int loc=strstr(str,".")-str;
    19         int loc1=strstr(str1,".")-str1;
    20 //        printf("==%d
    ",loc);
    21 //        int i=strlen(str);
    22 //        while(true)
    23 //        {
    24 //            if(str[i]=='')
    25 //            if(str[i-1]!='0')
    26 //            {
    27 //                str[i]='';
    28 //                break;
    29 //            }
    30 //            i++;
    31 //        }
    32         if(loc>loc1)
    33         {
    34             printf("Bigger
    ");
    35         }
    36         else if(loc<loc1)
    37         {
    38             printf("Smaller
    ");
    39         }
    40         else
    41         {
    42             int same=true;
    43             int len=strlen(str)<strlen(str1)?strlen(str):strlen(str1);
    44             for(int i=0;i<len;i++)
    45             {
    46                 if(str[i]=='.') continue;
    47                 if(str[i]>str1[i])
    48                 {
    49                     printf("Bigger
    ");
    50                     same=false;
    51                     break;
    52                 }
    53                 if(str[i]<str1[i])
    54                 {
    55                     printf("Smaller
    ");
    56                     same=false;
    57                     break;
    58                 }
    59             }
    60             
    61             ///判断出结果了其他循环就不要跑了
    62             if(same==false) continue;
    63             ///注意及时跳出
    64             
    65             if(strlen(str)==len)
    66             {
    67                 int len1=strlen(str1);
    68                 for(int i=len;i<len1;i++)
    69                 {
    70                     if(str1[i]!='0') {printf("Smaller
    ");same=false;}
    71                 }
    72             }
    73             else
    74             {
    75                 int len1=strlen(str);
    76                 for(int i=len;i<len1;i++)
    77                 {
    78                     if(str[i]!='0') {printf("Bigger
    ");same=false;}
    79                 }
    80             }
    81             if(same) printf("Same
    ");
    82         }
    83     }
    84     return 0;
    85 }/*
    86 
    87 1.0 2.0
    88 0.00001 0.00000
    89 0.0 0.000
    90 
    91 */
  • 相关阅读:
    AFNetworking使用总结
    使用Attiny 85开发板制作BadUSB
    C# 按指定数量从前面或者后面删除字符串
    C# 获取打印机列表
    【解决】该任务映像已损坏或已篡改。(异常来自HRESULT:0x80041321)
    PowerShell 解锁使用浏览器下载的文件
    C#使用HttpHelper万能框架,重启路由器
    【解决】应用程序无法正常启动(0xc000007b)。请单击“确定”关闭应用程序。
    Windows 7 IE11 F12 不能正常使用
    HTML5 图片上传预览
  • 原文地址:https://www.cnblogs.com/general10/p/6806296.html
Copyright © 2011-2022 走看看