이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dna.h"
#include <iostream>
#include <algorithm>
using namespace std;
string sa,sb;
void init(string a, string b) {
sa=a;
sb=b;
}
int get_distance(int x, int y) {
if(y-x<=2){
string a=sa.substr(x,y-x+1);
string b=sb.substr(x,y-x+1);
if(a==b) return 0;
string ca = a;
string cb = b;
sort(ca.begin(),ca.end());
sort(cb.begin(),cb.end());
if(ca != cb) return -1;
int cm = 0;
for(int i=0;i<a.size();i++){
if(a[i]==b[i]) cm++;
}
if(a.size()==3) return 2-cm;
if(a.size()==2) return 1-cm;
}
else{
string a=sa.substr(x,y-x+1);
string b=sb.substr(x,y-x+1);
if(a==b) return 0;
int ct1=0,ca1=0,ct2=0,ca2=0;
int cant_no_iguales=0;
for(int i=0;i<a.size();i++){
if(a[i]=='T'){
ct1++;
if(b[i]=='T'){
ct2++;
}
else{ // b[i]='A'
ca2++;
cant_no_iguales++;
}
}
else{ // a[i]='A'
ca1++;
if(b[i]=='A'){
ca2++;
}
else{ // b[i]='T'
ct2++;
cant_no_iguales++;
}
}
}
if(ca1==ca1 and ct1==ct2) return cant_no_iguales/2;
else return -1;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:25:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i=0;i<a.size();i++){
| ~^~~~~~~~~
dna.cpp:37:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i=0;i<a.size();i++){
| ~^~~~~~~~~
dna.cpp:59:9: warning: self-comparison always evaluates to true [-Wtautological-compare]
59 | if(ca1==ca1 and ct1==ct2) return cant_no_iguales/2;
| ~~~^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |