我是来吐槽poj的!!!
第一次做poj,被题目中的输入输出格式打败了 ,醉了醉了
Description
A research laboratory of a world-leading automobile company has received an order to create a special transmission mechanism, which allows for incredibly efficient kickdown — an operation of switching to lower gear. After several months of research engineers found that the most efficient solution requires special gears with teeth and cavities placed non-uniformly. They calculated the optimal flanks of the gears. Now they want to perform some experiments to prove their findings.
The first phase of the experiment is done with planar toothed sections, not round-shaped gears. A section of length n consists of n units. The unit is either a cavity of height h or a tooth of height 2h. Two sections are required for the experiment: one to emulate master gear (with teeth at the bottom) and one for the driven gear (with teeth at the top).
There is a long stripe of width 3h in the laboratory and its length is enough for cutting two engaged sections together. The sections are irregular but they may still be put together if shifted along each other.
The stripe is made of an expensive alloy, so the engineers want to use as little of it as possible. You need to find the minimal length of the stripe which is enough for cutting both sections simultaneously.
Input
There are two lines in the input file, each contains a string to describe a section. The first line describes master section (teeth at the bottom) and the second line describes driven section (teeth at the top). Each character in a string represents one section unit — 1 for a cavity and 2 for a tooth. The sections can not be flipped or rotated.
Each string is non-empty and its length does not exceed 100.
Output
Write a single integer number to the output file — the minimal length of the stripe required to cut off given sections.
Sample Input
sample input #1
2112112112
2212112 sample input #2
12121212
21212121
sample input #3 2211221122 21212
Sample Output
sample output #1
10 sample output #2
8 sample output #3
15 我一直以为输入输出中的”sample output #3“这玩意也要输入输出的就试了一下午!!
明明答案死活都对!!!简直被自己蠢哭了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
这是我第一次的代码,本来一次过的题!!!我的一下午!!!!!!!!!!!!!!
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int f(string a,string b)
{
int n1=a.length(),n2=b.length(),t=-,j=,k=;
for(int i=;i<n1;i++){
if((a[i]+b[j]-''*)<){
k=;
j++;
if(t==-)t=i;
}
else{
if(i==n1-&&j==)return n1+n2;
if(k==&&t!=-){
i=t;
t=-;
}
j=;
}
if(j==n2)return n1;
}
return t+n2;
}
int main()
{
string o1,o2,o3,a,b;
int k=,t;
while(cin>>o1>>o2>>o3){
cin>>a;
cin>>b;
int t1=t=f(b,a),t2=f(a,b);
if(t1>t2)t=t2;
printf("sample output #%d\n%d\n\n",k++,t);
}
return ;
}
这简直绝望了
各种改,试了无数组数据,真的绝望了!!!!!!!!!!!!!!
再看了AC代码后,真的要哭了..............
改完AC..............
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
char a[],b[];
int f(char* a,char* b)
{
int n1=strlen(a),n2=strlen(b),t=-,j=,k=;
for(int i=;i<n1;i++){
if((a[i]+b[j]-''*)<){
k=;
j++;
if(t==-)t=i;
}
else{
if(i==n1-&&j==)return n1+n2;
if(k==&&t!=-){
i=t;
t=-;
}
j=;
}
if(j==n2)return n1;
}
return t+n2;
}
int main()
{
int t;
while(cin>>a>>b){
int t1=t=f(b,a),t2=f(a,b);
if(t1>t2)t=t2;
printf("%d\n",t);
}
return ;
}
题目要求两块木头不能旋转,若可以旋转,将一个字符串倒过来即可
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
//char d[110]; //旋转
char a[],b[];
int f(char* a,char* b)
{
int n1=strlen(a),n2=strlen(b),t=-,j=,k=;
for(int i=;i<n1;i++){
//printf("a[%d]+b[%d]=%c+%c=%d\n",i,j,a[i],b[j],a[i]+b[j]-'0'*2);
if((a[i]+b[j]-''*)<){
k=;
j++;
//cout<<"i"<<i<<endl;
if(t==-)t=i;
}
else{
if(i==n1-&&j==)return n1+n2;
if(k==&&t!=-){
i=t;
//cout<<"i"<<i<<endl;
t=-;
}
j=;
}
if(j==n2)return n1;
}
return t+n2;
}
/*char* g(string a) // 旋转
{
int n=a.length();
for(int i=0;i<n;i++)d[i]=a[n-1-i];
d[n]='\0';
return d;
}*/
int main()
{
int k=,t;
while(cin>>a>>b){
int t1=t=f(b,a),t2=f(a,b);//,n=a.length(); //旋转
if(t1>t2)t=t2;
/*string c=g(a); // 旋转
t1=f(c,b),t2=f(b,c);
if(t1>t2)t1=t2;
if(t>t1)t=t1;*/
printf("sample output #%d\n%d\n\n",k++,t);
}
return ;
}