26 条题解

  • 1
    @ 2020-08-30 15:32:44

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <iostream>
    #include <string>
    using namespace std;
    int T;
    char c;
    string s;
    int a[10],ans;
    int main(){
    //freopen("data.txt","r",stdin);
    scanf("%d",&T);
    while((c=getchar())==' ');
    for(int k=1;k<=T;k++){
    memset(a,0,sizeof(a));
    getline(cin,s);
    int l=s.size();
    for(int i=0;i<l;i++){
    if(s[i]==' ') a[1]++;
    if(s[i]=='g') a[2]++;
    if(s[i]=='o') a[3]++;
    if(s[i]=='d') a[4]++;
    if(s[i]=='m') a[5]++;
    if(s[i]=='r') a[6]++;
    if(s[i]=='n') a[7]++;
    if(s[i]=='i') a[8]++;
    }
    a[2]/=2;
    a[3]/=3;
    a[7]/=2;
    sort(a+1,a+9);
    ans=a[1];
    printf("Case #%d: %d\n",k,ans);
    }
    return 0;
    }

  • 0
    @ 2015-07-20 22:25:45

    字符串处理太坑啦。。。。。c++表示摸不清换行的头脑,被‘\r’坑了

  • 0
    @ 2015-02-15 17:13:13

    time = int(raw_input())
    run_time = 0

    while run_time < time:
    txt = list(raw_input())
    i = 0
    stop = False

    while not stop:
    for s in "good morning":
    try:
    txt.remove(s)
    except:
    print "Case #{}: {}".format(run_time + 1, i / len("good morning"))
    stop = True
    break
    i += 1
    run_time += 1

  • 0
    @ 2014-12-18 17:58:24

    题目网址 https://vijos.org/p/1902/solution

    这是到很简单的计数题。

    先看题目,发现数据长度(字符串)大于225,所以不能用string(我死这里过)要ansistring,不然只有40分。

    good morning,每个当作一个字符,要想知道能最多组成几个good morning首先要知道每个字符有几个。

    就像做车,需要零件,一个good morning需要2个g,3个o,以此类推。

    先通过case of把所有字符存下来,然后g div 2(因为2个G才能组成一个,以此类推)最后输出最缺少的那个"零件",比如G有4个可以组成2个good morning,但是i只有1个,只能组成一个,所以顶多也只能组成一个,因为i不够。

  • 0
    @ 2014-12-15 20:47:44

    草了,没用ansistring40分N次,我就说嘛- -怎么会错呢、、

  • 0
    @ 2014-11-06 21:27:56

    PAS AC100
    var
    str:ansistring;
    i,j,n,len,max:integer;
    c:array [1..8] of integer;
    begin
    readln(n);
    for i:=1 to n do
    begin
    fillchar(c,sizeof(c),0);
    readln(str);
    len:=length(str);
    for j:=1 to len do
    case str[j] of
    'g':inc(c[1]);
    'o':inc(c[2]);
    'd':inc(c[3]);
    'm':inc(c[4]);
    'r':inc(c[5]);
    'n':inc(c[6]);
    'i':inc(c[7]);
    ' ':inc(c[8]);
    end;
    c[1]:=c[1] div 2;
    c[2]:=c[2] div 3;
    c[6]:=c[6] div 2;
    max:=1000;
    for j:=1 to 8 do if c[j]<max then max:=c[j];
    writeln('Case #',i,': ',max);
    end;
    end.

  • 0
    @ 2014-11-06 07:35:56

    writeln('Case #',i,': ',A[1]);

  • 0
    @ 2014-11-02 19:43:33

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    using namespace std;
    int t,cnt;
    char ch;
    char s[1010];
    int main()
    {
    //freopen("1902.in","r",stdin);
    //freopen("1902.out","w",stdout);
    scanf("%d\n",&t);
    for(int i=1;i<=t;i++)
    {
    int gg=0,oo=0,dd=0,mm=0,rr=0,nn=0,ii=0,kong=0;
    while((ch=getchar())!='\n'&&ch!=-1)
    {
    if(ch=='g') gg++;
    else if(ch=='o') oo++;
    else if(ch=='d') dd++;
    else if(ch=='m') mm++;
    else if(ch=='r') rr++;
    else if(ch=='n') nn++;
    else if(ch=='i') ii++;

    else if(ch==' ') kong++;
    }
    int ans=gg/2;
    ans=min(ans,oo/3);
    ans=min(ans,dd);
    ans=min(ans,mm);
    ans=min(ans,rr);
    ans=min(ans,nn);
    ans=min(ans,ii);
    ans=min(ans,kong);
    printf("Case #%d: %d\n",i,ans);
    scanf("\n");
    }
    return 0;
    }
    求解错在哪里

  • 0
    @ 2014-11-02 18:52:02

    #include<cstdio>
    #include<cstring>
    int main()
    {
    int T,ch,ans,num[8];scanf("%d",&T);
    while((ch=getchar())==' ');
    for(int kase=1;kase<=T;++kase)
    {
    printf("Case #%d: ",kase);
    memset(num,0,sizeof(num));
    for(;(ch=getchar())!=EOF;)
    {
    if(ch=='\n')break;
    switch(ch)
    {
    case 'g':++num[0];break;
    case 'o':++num[1];break;
    case 'd':++num[2];break;
    case ' ':++num[3];break;
    case 'm':++num[4];break;
    case 'r':++num[5];break;
    case 'n':++num[6];break;
    case 'i':++num[7];break;
    default :break;
    }
    }
    num[0]/=2;num[1]/=3;num[6]/=2;ans=1001;
    for(int i=0;i<8;++i)if(num[i]<ans)ans=num[i];
    printf("%d\n",ans);
    }
    return 0;
    }

  • 0
    @ 2014-11-02 18:50:31

    #include<cstdio>
    #include<cstring>
    int main()
    {
    int T,ch,ans,num[8];scanf("%d",&T);while((ch=getchar())==' ');
    for(int kase=1;kase<=T;++kase)
    {
    printf("Case #%d: ",kase);
    memset(num,0,sizeof(num));
    for(;(ch=getchar())!=EOF;)
    {
    if(ch=='\n')break;
    switch(ch)
    {
    case 'g':++num[0];break;
    case 'o':++num[1];break;
    case 'd':++num[2];break;
    case ' ':++num[3];break;
    case 'm':++num[4];break;
    case 'r':++num[5];break;
    case 'n':++num[6];break;
    case 'i':++num[7];break;
    default :break;
    }
    }
    num[0]/=2;num[1]/=3;num[6]/=2;ans=1001;
    for(int i=0;i<8;++i)if(num[i]<ans)ans=num[i];
    printf("%d\n",ans);
    }
    return 0;
    }

  • 0
    @ 2014-11-02 17:03:39

    考试的时候没用**ansistring**,结果只过了4个点......
    Accepted, time = 90 ms, mem = 1812 KiB, score = 100

    var
    tIn,t:byte;
    len,i,blank,min:integer;
    str:ansistring;
    a:array['a'..'z'] of integer;
    num:array[1..8] of integer;
    procedure main;
    begin
    for i:=1 to len do
    case str[i] of
    'd':inc(a['d']);
    'm':inc(a['m']);
    'r':inc(a['r']);
    'i':inc(a['i']);
    'g':inc(a['g']);
    'n':inc(a['n']);
    'o':inc(a['o']);
    ' ':inc(blank);
    end;
    num[1]:=a['d'];num[2]:=a['m']; num[3]:=a['r'];num[4]:=a['i'];
    num[5]:=a['g'] div 2;num[6]:=a['n'] div 2;
    num[7]:=a['o'] div 3;num[8]:=blank;
    for i:=1 to 8 do
    if num[i]<min then min:=num[i];
    writeln('Case #',t,': ',min);
    end;
    begin
    readln(tIn);
    for t:=1 to tIn do
    begin
    readln(str);
    len:=length(str);
    fillchar(num,sizeof(num),0);
    fillchar(a,sizeof(a),0);
    blank:=0;min:=32767;
    main;
    end;
    end.

  • 0
    @ 2014-11-02 15:37:24

    var s:ansistring;
    n,i,num:longint;
    a:array[1..8] of longint;
    function pd:longint;
    var i,j,total:longint;
    begin
    total:=0;
    for i:=1 to maxlongint do
    begin
    for j:=1 to 8 do
    begin
    if a[j]>0 then
    dec(a[j])
    else
    exit(total);
    end;
    inc(total);
    end;
    end;

    begin
    readln(n);
    for num:=1 to n do
    begin
    readln(s);
    for i:=1 to length(s) do
    begin
    if s[i]='g' then
    inc(a[1]);
    if s[i]='o' then
    inc(a[2]);
    if s[i]='d' then
    inc(a[3]);
    if s[i]=' ' then
    inc(a[4]);
    if s[i]='m' then
    inc(a[5]);
    if s[i]='r' then
    inc(a[6]);
    if s[i]='n' then
    inc(a[7]);
    if s[i]='i' then
    inc(a[8]);
    end;
    a[1]:=a[1] div 2;
    a[2]:=a[2] div 3;
    a[7]:=a[7] div 2;
    writeln('Case #',num,': ',pd);
    end;
    end.
    各位大神,哪里错了?为什么只过两组??!!!!!!!!!

  • 0
    @ 2014-11-02 15:21:24

    表示一次AC无压力;
    var
    art:ansistring;
    s:array['a'..'z'] of longint;
    i,j,t,sp:longint;
    begin
    readln(t);
    for i:=1 to t do
    begin
    sp:=0;
    fillchar(s,sizeof(s),0);
    readln(art);
    for j:=1 to length(art) do
    if art[j]=' ' then inc(sp)
    else inc(s[art[j]]);
    if s['g'] div 2<sp then sp:=s['g'] div 2;
    if s['o'] div 3<sp then sp:=s['o'] div 3;
    if s['d']<sp then sp:=s['d'];
    if s['m']<sp then sp:=s['m'];
    if s['r']<sp then sp:=s['r'];
    if s['n'] div 2<sp then sp:=s['n'] div 2;
    if s['i']<sp then sp:=s['i'];
    writeln('Case #',i,': ',sp);
    end;
    end.

  • 0
    @ 2014-11-02 14:16:58

    这一题出数据的人很狡猾, 似乎所有奇怪的数据他都用了.

  • 0
    @ 2014-11-02 14:16:17
  • 0
    @ 2014-11-02 11:29:30

    测试数据 #0: Accepted, time = 15 ms, mem = 508 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 508 KiB, score = 10
    测试数据 #2: Accepted, time = 15 ms, mem = 508 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 504 KiB, score = 10
    测试数据 #4: Accepted, time = 31 ms, mem = 504 KiB, score = 10
    测试数据 #5: Accepted, time = 31 ms, mem = 508 KiB, score = 10
    测试数据 #6: Accepted, time = 31 ms, mem = 508 KiB, score = 10
    测试数据 #7: Accepted, time = 31 ms, mem = 504 KiB, score = 10
    测试数据 #8: Accepted, time = 31 ms, mem = 504 KiB, score = 10
    测试数据 #9: Accepted, time = 31 ms, mem = 508 KiB, score = 10
    Accepted, time = 216 ms, mem = 508 KiB, score = 100
    代码
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <iostream>
    #include <string>
    using namespace std;
    int T;
    char c;
    string s;
    int a[10],ans;
    int main(){
    //freopen("data.txt","r",stdin);
    scanf("%d",&T);
    while((c=getchar())==' ');
    for(int k=1;k<=T;k++){
    memset(a,0,sizeof(a));
    getline(cin,s);
    int l=s.size();
    for(int i=0;i<l;i++){
    if(s[i]==' ') a[1]++;
    if(s[i]=='g') a[2]++;
    if(s[i]=='o') a[3]++;
    if(s[i]=='d') a[4]++;
    if(s[i]=='m') a[5]++;
    if(s[i]=='r') a[6]++;
    if(s[i]=='n') a[7]++;
    if(s[i]=='i') a[8]++;
    }
    a[2]/=2;
    a[3]/=3;
    a[7]/=2;
    sort(a+1,a+9);
    ans=a[1];
    printf("Case #%d: %d\n",k,ans);
    }
    return 0;
    }

    比赛的时候爆零了TAT
    然后发现是数组后面的空格的问题
    而且要注意T后面的空格貌似不止一个?
    改成 getchar(); //组数后面的空格
    getchar();//换行符;
    这样wa了两个点;
    改成 while(c==getchar()==' ') 就A了
    QAQ 字符串有时候真的好坑;

  • 0
    @ 2014-11-02 11:18:34

    第一个点T
    第二个点 W了
    咋回事啊?。
    #include<cstdio>
    inline int min(int a,int b){return a>b?b:a;}
    int main(){
    int n,i=1;
    scanf("%d\n",&n);
    while(n--){
    int G,O,D,M,N,I,R,K;
    G=O=D=M=N=I=R=K=0;
    char ch;
    while((ch=getchar())!='\n'){
    if(ch==' ')K++;
    if(ch=='g')G++;
    if(ch=='d')D++;
    if(ch=='o')O++;
    if(ch=='m')M++;
    if(ch=='n')N++;
    if(ch=='i')I++;
    if(ch=='r')R++;
    }
    G/=2;
    N/=2;
    O/=3;
    G=min(G,K);
    G=min(G,D);
    G=min(G,O);
    G=min(G,M);
    G=min(G,N);
    G=min(G,I);
    G=min(G,R);
    printf("Case #%d: %d\n",i,G);
    i++;
    }
    }

    • @ 2014-11-02 14:17:36

      第一个点. 我记得里面有空行(空行的答案当然是0)

  • 0
    @ 2014-11-02 11:08:23

    program wenhou;
    var
    a:ansistring;
    t,i,j,z,k:longint;
    b:array[1..200] of longint;
    begin
    readln(t);
    for j:=1 to t do
    begin
    readln(a);
    for i:=1 to length(a) do
    begin
    if a[i]='g' then b[1]:=b[1]+1;
    if a[i]='o' then b[2]:=b[2]+1;
    if a[i]='d' then b[3]:=b[3]+1;
    if a[i]=' ' then b[4]:=b[4]+1;
    if a[i]='m' then b[5]:=b[5]+1;
    if a[i]='r' then b[6]:=b[6]+1;
    if a[i]='n' then b[7]:=b[7]+1;
    if a[i]='i' then b[8]:=b[8]+1;
    end;
    b[1]:=b[1] div 2;
    b[2]:=b[2] div 3;
    b[7]:=b[7] div 2;

    k:=b[1];
    for i:=2 to 8 do if b[i]<k then k:=b[i];
    writeln('Case #',j,': ',k);
    for i:=1 to 8 do b[i]:=0;
    end;
    end.
    弄了好久才AC。
    气死我了,输出数据Case #1:1 冒号后面有个空格!!!!!! 以后可得注意!

  • 0
    @ 2014-11-02 10:52:34

    哪里错了???var a,b,c,e,min:longint;
    f:ansistring;
    g:array[1..8]of longint;
    d:array[1..20]of longint;
    begin
    readln(a);
    for b:=1 to a do
    begin
    readln(f);
    for c:=1 to length(f) do
    begin
    case f[c] of
    'g':inc(g[1]);
    'o':inc(g[2]);
    'd':inc(g[3]);
    'm':inc(g[4]);
    'r':inc(g[5]);
    'n':inc(g[6]);
    'i':inc(g[7]);
    ' ':inc(g[8]);
    end;
    end;
    g[1]:=g[1] div 2;
    g[2]:=g[2] div 3;
    g[6]:=g[6] div 2;
    min:=maxlongint;
    for c:=1 to 8 do
    if g[c]<min then min:=g[c];
    d[b]:=min;
    f:='';
    for c:=1 to 8 do g[c]:=0;
    end;
    for c:=1 to a do writeln('Case #',c,': ',d[c]);
    end.

    • @ 2014-11-02 11:00:20

      我和你的做法一样,不知道为什么不过?

  • 0
    @ 2014-11-02 10:45:07

    到底哪里错了????求大神指点??为什么运行错误???

    program wenhou;
    var
    a:array[0..50] of ansistring;
    t,i,j,z,k:longint;
    b:array[1..200] of longint;
    begin
    readln(t);
    for j:=1 to t do
    readln(a[j]);
    for j:=1 to t do
    begin
    for i:=1 to length(a[j]) do
    begin
    if a[j][i]='g' then b[1]:=b[1]+1;
    if a[j][i]='o' then b[2]:=b[2]+1;
    if a[j][i]='d' then b[3]:=b[3]+1;
    if a[j][i]=' ' then b[4]:=b[4]+1;
    if a[j][i]='m' then b[5]:=b[5]+1;
    if a[j][i]='r' then b[6]:=b[6]+1;
    if a[j][i]='n' then b[7]:=b[7]+1;
    if a[j][i]='i' then b[8]:=b[8]+1;
    end;
    b[1]:=b[1] div 2;
    b[2]:=b[2] div 3;
    b[7]:=b[7] div 2;

    k:=b[1];
    for i:=2 to 8 do if b[i]<k then k:=b[i];
    writeln('Case',' ','#',j,':',k);
    for i:=1 to 8 do b[i]:=0;
    end;
    end.

信息

ID
1902
难度
7
分类
(无)
标签
(无)
递交数
1572
已通过
340
通过率
22%
被复制
6
上传者