题目问答
题目问答简介
为何逻辑相似,只是换用了数据输入方式,就能AC?
下面这是我让AI写的代码,后面接着我的代码,看着除了输入方式不一样之外,好像就没什么差别了,想不明白为什么我自己的代码AC不了,AI的却可以。。。。求大佬解答,感谢
```cpp
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
struct Student {
string name;
int id;
string className;
};
// 比较函数
bool compare(const Student& lhs, const Student& rhs) {
if (lhs.className != rhs.className) {
return lhs.className < rhs.className;
}
return lhs.id < rhs.id;
}
int main() {
// 优化 I/O 速度
ios::sync_with_stdio(false);
cin.tie(0);
int n;
// 尝试处理多组输入,防止 WA
while (cin >> n) {
vector<Student> students(n);
for (int i = 0; i < n; ++i) {
cin >> students[i].name >> students[i].id >> students[i].className;
}
sort(students.begin(), students.end(), compare);
for (const auto& s : students) {
cout << s.name << " " << s.id << " " << s.className << endl;
}
}
return 0;
}
```
```cpp
#include <cstdio>
#include "string"
#include "vector"
#include "algorithm"
using namespace std;
struct Student{
string name;
int id;
string className;
Student(char *_name, int _id, char *_className){
name = _name;
id = _id;
className = _className;
}
};
bool compare(Student lhs, Student rhs){
if(lhs.className < rhs.className) return true;
else if(lhs.className == rhs.className && lhs.id < rhs.id) return true;
else return false;
}
int main() {
vector<Student> students;
int n, id;
char buffer_name[50], buffer_className[50];
while (scanf("%d", &n) != EOF){
students.clear();
while (n --){
scanf("%s %d %s", buffer_name, &id, buffer_className);
students.emplace_back(buffer_name, id, buffer_className);
}
sort(students.begin(), students.end(), compare);
for(auto each: students){
printf("%s %d %s\n", each.name.c_str(), each.id, each.className.c_str());
}
}
return 0;
}
```
查看全文
1
0
0
14
求解代码问题,通过了三个案例
```c
[[
int uniquely(MGraph G) {
int v=G.numberVertices;
if (v==0) return 1;
int i=0,j=0,k=0,flag=-1;
for(k=0;k<v;v++){
flag=-1;
for(i=0;i<v;i++){
for(j=0;j<v;j++){
if(G.edge[j][i]) break;
}
if(j==v){
if (flag!=-1) return 0;
flag=i;
}
}
if(flag==-1) return 0;
for(int i=0;i<v;i++){
G.edge[flag][i]=0;
}
}
return 1;
}
```
查看全文
1
0
0
35
数据是不是弱了
试一下这组 hack
```text
10 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
```
查看全文
4
0
0
106
问题出在哪了捏
```cpp
#include<bits/stdc++.h>
using namespace std;
int m1[]={0,1,3,5,7,8,10,12};//数组m1存储大月
int m2[]={0,4,6,9,11};//数组m2存储小月
map<int,int> bh={{0,13},{1,1},{2,2},{3,3},{4,5},{5,4},{6,4},{7,2},{8,2},{9,2}};
int sum(int year,int month,int day){
int y1=year%10,y2=year%100,y3=year%1000,y4=year/1000;
int m1=month%10,m2=month/10;
int d1=day%10,d2=day/10;
int n=0;
n=bh[y1]+bh[y2]+bh[y3]+bh[y4]+bh[m1]+bh[m2]+bh[d1]+bh[d2];
return n;
}
int main(){
int num=0;
int year=2000,month=1,day=1;
int year2=2024,month2=4,day2=13;
while(1){
if(sum(year,month,day)>50) num++;
day++;
for(int j=1;j<=7;j++){
if(month==m1[j]&&day==32){
month++;
day=1;
break;
}
}
for(int j=1;j<=4;j++){
if(month==m2[j]&&day==31){
month++;
day=1;
break;
}
}
if(month==2){
if((year%4==0&&year%100!=0)||year%400==0){
if(day==30){
month++;
day=1;
}
}else{
if(day==29){
month++;
day=1;
}
}
}
if(month==13){
month=1;
year++;
}
if(year==year2&&month==month2&&day==day2) break;
}
cout<<num<<endl;
return 0;
}
```
查看全文
2
0
0
40



