您的位置:首页 > 编程语言 > C语言/C++

PAT 1058. 选择题(20) C++

2017-12-23 14:51 453 查看
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
using namespace std;

int main()
{
int N,M;
cin>>N>>M;
getchar();
int score[M];
int Cnum[4];
int Tnum[4];
char answer[1000];
string str1[M];
for(int i=0;i<M;i++) {
char answer[1000]={""};
cin>>score[i]>>Cnum[i]>>Tnum[i];
for(int j=0;j<Tnum[i];j++) {
cin>>answer[j];
}
str1[i] = answer;
//cout<<str1[M-1]<<" ";

}

//for(int i=0;i<M;i++){
//      cout<<str1[i]<<" ";
//	}

int choose;
char ans[1000];
string str2[M];
int sum[1000]={0};
int num[1000]={0};

//for(int i=0;i<M;i++){
//    cout<<score[i]<<endl;
//}

for(int i=0;i<N;i++) {
scanf("\n");	//格式部分
for(int k=0;k<M;k++) {
if(k != 0) scanf(" ");
char ans[1000]={""};
scanf("(%d", &choose);
//cin>>choose;
for(int j=0;j<choose;j++) {
cin>>ans[j];
}
scanf(")");
str2[k] = ans;

//cout<<str2[k]<<" ";
//cout<<str1[k]<<endl<<str2[k]<<endl;

if(str1[k]==str2[k]) {
sum[i]=sum[i]+score[k];
}else {
num[k]++;
}
//cout<<sum[i]<<endl;
}
}
for(int i=0;i<N;i++) {
cout<<sum[i]<<endl;
}
int tig=0,max=0;
for(int i=0;i<M;i++) {
tig+=num[i];
}
if(tig==0) {
cout<<"Too simple";
}else {
for(int j=0;j<M;j++) {
if(num[j]>max)
{
max=num[j];
}
}
cout<<max;
for(int z=0;z<M;z++) {
if(max==num[z]) {
cout<<" "<<z+1;
}
}
}
return 0;
}

输入()格式部分改了好多次,还有段错误。

下面是没有写格式的java代码。真心写不下去,格式太难整了qaq。

import java.util.Scanner;
public class Main {
public static void main
a74e
(String[] args) {
Scanner sc=new Scanner(System.in);
int N = sc.nextInt();
int M = sc.nextInt();
int[] score = new int[M];
int[] Cnum = new int[4];
int[] Tnum = new int[4];
String[] answer = new String[4];
String[] str1 = new String[M];
for(int i=0;i<M;i++) {
score[i] = sc.nextInt();
Cnum[i] = sc.nextInt();
Tnum[i] = sc.nextInt();
for(int j=0;j<Tnum[i];j++) {
answer[j] = sc.next();
}
for(int z=0;z<Tnum[i];z++) {
str1[i] = str1[i]+answer[z];
}
}

//for(int i=0;i<M;i++) {
//System.out.print(score[i]+" ");
// System.out.print(str1[i]+" ");
// System.out.println();
//}//

int choose;
String[] ans = new String[4];
String[] str2 = new String[M];
String[] ch = new String[M];
int[] sum=new int[M];
int[] num=new int[M];
for(int i=0;i<N;i++) {
for(int k=0;k<M;k++) {
//char left = System.in.read();
//char getChar = sc.nextLine().charAt(0);
// for(int q=0;q<1;q++) {
// char c = sc.next().charAt(0);
// }
choose = sc.nextInt();
for(int j=0;j<choose;j++) {
ans[j] = sc.next();
}
for(int z=0;z<choose;z++) {
str2[k] = str2[k]+ans[z];
}
if(str1[k].equals(str2[k])) {
sum[i]=sum[i]+score[k];
}else {
num[k]++;
}
//char right = sc.next().charAt(0);
//char getChar2 = sc.nextLine().charAt(0);
// for(int q=0;q<1;q++) {
// char c = sc.next().charAt(0);
// }
}
//for(int a=0;a<M;a++) {
// System.out.print(str2[a]+" ");
// }//

//for(int d=0;d<M;d++) {
//System.out.println("str1: "+str1[d]+" "+"str2: "+str2[d]);
//}
for(int d=0;d<M;d++) {
str2[d]=null;
}
}
for(int i=0;i<N;i++) {
System.out.println(sum[i]);
}
int tig=0,temp;
for(int i=0;i<M;i++) {
tig+=num[i];
}
if(tig==0) {
System.out.print("Too simple");
}else {
for(int j=0;j<M;j++) {
for(int k=j+1;k<M;k++) {
if(num[j]>num[k]) {
temp=num[k];
num[k]=num[j];
num[j]=temp;
}
}
}
System.out.print(num[M-1]+" ");
for(int z=0;z<M;z++) {
if(num[M-1]==num[z]) {
System.out.print((z+1)+" ");
}
}
}
sc.close();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息