#16098: C++解


love1245672@gmail.com (李奧尿多)

學校 : 大甲國中
編號 : 88384
來源 : [114.137.14.241]
最後登入時間 :
2020-08-02 14:21:35
c276. 沒有手機的下課時間 -- 板橋高中教學題 | From: [42.72.101.98] | 發表日期 : 2018-11-20 20:33

#include<iostream>
#include<vector>
#include<string>
using namespace std;

int main()
{
int time;
string anwser;
while (cin >> anwser >> time)
{
int *A = new int[time]();
int *B = new int[time]();
string* word = new string[time];
for (int i = 0; i < time; i++)
cin >> word[i];
for (int i = 0; i < time; i++)
for (int j = 0; j < anwser.size(); j++)
if (anwser[j] == word[i][j])
{
word[i][j] = 'A';
A[i]++;
}
for (int i = 0; i < time; i++)
for (int j = 0; j < anwser.size(); j++)
for(int a = 0; a < anwser.size(); a++)
if (anwser[j] == word[i][a])
{
word[i][a] = 'B';
B[i]++;
}
for (int i = 0; i < time; i++)
cout << A[i] << "A" << B[i] << "B\n";
}
}

 
#18825: Re:C++解


kentsai1688@gmail.com (Ken Tsai)

學校 : 國立科學工業園區實驗高級中學
編號 : 99014
來源 : [118.163.197.175]
最後登入時間 :
2020-07-19 18:20:13
c276. 沒有手機的下課時間 -- 板橋高中教學題 | From: [123.240.239.161] | 發表日期 : 2019-08-07 14:02

#include
#include
#include
using namespace std;

int main()
{
int time;
string anwser;
while (cin >> anwser >> time)
{
int *A = new int[time]();
int *B = new int[time]();
string* word = new string[time];
for (int i = 0; i < time; i++)
cin >> word[i];
for (int i = 0; i < time; i++)
for (int j = 0; j < anwser.size(); j++)
if (anwser[j] == word[i][j])
{
word[i][j] = 'A';
A[i]++;
}
for (int i = 0; i < time; i++)
for (int j = 0; j < anwser.size(); j++)
for(int a = 0; a < anwser.size(); a++)
if (anwser[j] == word[i][a])
{
word[i][a] = 'B';
B[i]++;
}
for (int i = 0; i < time; i++)
cout << A[i] << "A" << B[i] << "B\n";
}
}

 

#include <cstdio>

using namespace std;

bool Number[10]={0};

char ch,guess[4],ans[4];

int n,A,B;

int main()

{

    for(int i=0;i<4&&scanf("%c",&ch);Number[ch-'0']=true,ans[i]=ch,i++);

    scanf("%d",&n);

    while(n--&&getchar())

    {

        A=B=0;

        for(int i=0;i<4&&scanf("%c",&ch);guess[i]=ch,i++)

            if(Number[ch-'0']) B++;

        for(int i=0;i<4;i++)

            if(guess[i]==ans[i]) A++,B--;

        printf("%dA%dB\n",A,B);

    }

    return 0;

}

//(1ms, 100KB)

 

 
ZeroJudge Forum