我是来吐槽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 ;
}

poj 3158kickdown的更多相关文章

  1. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  2. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  3. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  4. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  5. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  6. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  7. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  8. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

  9. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

随机推荐

  1. Spring中的WebDataBinder浅析

    Spring可以自动封装Bean,也就是说可以前台通过SpringMVC传递过来的属性值会自动对应到对象中的属性并封装成javaBean,但是只能是基本数据类型(int,String等).如果传递过来 ...

  2. Android应用中MVP最佳实践

    转自:http://www.jianshu.com/p/ed2aa9546c2c 文/Jude95(简书作者)原文链接:http://www.jianshu.com/p/ed2aa9546c2c著作权 ...

  3. python中的 json 模块使用

    (1)python 中生成 json 字符串: import json data = dict(ret=0, msg="Welcome, Login success!") json ...

  4. awk多个数组的使用

    #!/bin/bash awk 'BEGIN{printf "%-60s %-10s %-10s %-10s\n","url","count" ...

  5. python functools.wraps装饰器模块

    # -*-coding=utf-8 -*-#实现一个函数执行后计算执行时间的功能 __author__ = 'piay' import time, functools def foo(): ''' 定 ...

  6. mongodb 基本语法

    成功启动MongoDB后,再打开一个命令行窗口输入mongo,就可以进行数据库的一些操作. 输入help可以看到基本操作命令: show dbs:显示数据库列表 show collections:显示 ...

  7. 小SQL大作用

    从DBA那问来的,备份现有数据库表: create table B select * from A ; 删除,重建数据库主键 alter table book_order drop primary k ...

  8. spring的数据源基本配置

    aplictaionContext-dataSource的配置: <?xml version="1.0" encoding="utf-8"?> &l ...

  9. ORA-19573: cannot obtain exclusive enqueue for datafile 1

    还原Oracle数据库时出现ORA-19870和ORA-19573错误,如: RMAN> restore database; Starting restore at 11-DEC-12 usin ...

  10. sqlplus 一次奇葩问题 HTTP proxy setting has incorrect value

    y@y:~$ sqlplus Error 46 initializing SQL*PlusHTTP proxy setting has incorrect valueSP2-1502: The HTT ...