求个大佬来看看呀这种函数该则么传值= =
这题也不难,但是写起来巨麻烦做得令人暴躁!不写了就这样吧
语法编译不通过的错解:
#include<cstdio>
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<cctype>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<string.h>
using namespace std;
#define N 10
int judge(void const*a_t, void const*b_t)//不知道怎样用函数指针
{
char*a=(char *)a_t;
char *b=(char*)b_t;
if(((*a=='C')&&(*b=='J'))||((*a=='J')&&(*b=='B'))||((*a=='B')&&(*b=='C'))) return 1;
else if(((*b=='C')&&(*a=='J'))||((*b=='J')&&(*a=='B'))||((*b=='B')&&(*a=='C'))) return 2;
else return 0;}
int main()
{
int n=0,sx=0,sy=0,xy=0;
cin>>n;
char x,y;
while(n--)
{
cin>>x>>y;
if(judge(x,y)==1) sx++;
else if(judge(x,y)==2) sy++;
else xy++;
}
cout<<sx<<" "<<xy<<" "<<sy<<endl;
cout<<sy<<" "<<xv<<" "<<sx<<endl;
return 0;
}
一个清奇的思路:
#include <iostream>
using namespace std;
int win[3] = {0};
char max3(int *a) {
char r = 'B';
if(a[1] > a[0]) {
a[0] = a[1];
r = 'C';
}
if(a[2] > a[0]) r = 'J';
return r;
}
int main() {
int n;
char a[105],b[105];
int awin[3] = {0};
int bwin[3] = {0};
cin >> n;
for(int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
int k = (a[i] - b[i]) * (a[i] - b[i]);
if(k == 1)
a[i] == 66 ? win[0]++,awin[0]++ : (win[1]++,bwin[0]++);
else if(k == 49)
a[i] == 67 ? win[0]++,awin[1]++ : (win[1]++,bwin[1]++);
else if(k == 64)
a[i] == 74 ? win[0]++,awin[2]++ : (win[1]++,bwin[2]++);
else
win[2]++;
}
cout << win[0] << " " << win[2] << " " << win[1] << endl;
cout << win[1] << " " << win[2] << " " << win[0] << endl;
cout << max3(awin) << " " << max3(bwin);
return 0;
}