POJ 1298
来源:互联网 发布:商业源码 编辑:程序博客网 时间:2024/06/03 05:45
最近准备开始练习一下poj上的程序,先从水题开始吧,这就是第一个选择的题,题目果然很简单,密码翻译,对于不属于字母的元素直接输出,对于大写字母,减五就能得到翻译后的结果,除A~E需要特殊处理
本以为可以轻松过关,不过一运行报Time Limit Exceeded,需要进一步的调试
#include<iostream>
#include<string.h>
using namespace std;
char decode(char character){
char*result;
switch(character)
{
case 'A':
return 'V';
break;
case 'B':
return 'W';
break;
case 'C':
return 'X';
break;
case 'D':
return 'Y';
break;
case 'E':
return 'Z';
break;
default:
return character-5;
break;
}
}
int main(){
char input[11];
char Cipher[201];
char end[4];
int i;
while(1)
{
cin.getline(input,11);
if(input == "ENDOFINPUT")
break;
else{
cin.getline(Cipher,201);
int length=strlen(Cipher);
for(i=0;i<length;i++)
{
if(Cipher[i] <= 'Z' && Cipher[i] >= 'A'){
// cout<<'1';
cout << decode(Cipher[i]);
}
else
{
//cout<<'0';
cout << Cipher[i];
}
}
cout<<endl;
cin.getline(end,4);
}
// cout<<end<<endl;
}
return 0;
}
不用函数调用,采用scanf与printf进行输入输出之后可以AC.
#include<stdio.h>
#include<string.h>
char result[27]="VWXYZABCDEFGHIJKLMNOPQRSTU";
int main(){
char Cipher[201];
char input[11];
char end[4];
int i;
while(1)
{
//scanf("%s",input);
//cin.getline(input,11);
scanf("%s%*c",input);
if(strcmp(input,"ENDOFINPUT")==0)
break;
else{
//cin.getline(Cipher,201);
gets(Cipher);
//printf("%d\n",strlen(Cipher));
int length=strlen(Cipher);
for(i=0;i<length;i++)
{
if(Cipher[i] <= 'Z' && Cipher[i] >= 'A'){
printf("%c",result[Cipher[i]-'A']);
//cout << result[Cipher[i]-'A'];
}
else
{
printf("%c",Cipher[i]);
// cout << Cipher[i];
}
}
printf("\n");
//cout<<endl;
//scanf("%s",end);
//cin.getline(end,4);
scanf("%s%*c",end);
}
}
}
- POJ 1298
- poj 1298
- POJ 1298
- poj 1298【STL string】
- POJ 1298 解密
- POJ 1298 解题报告
- POJ 1298 解密加密
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POOMKONKONK
- 二叉排序树的删除
- 用3个步骤实现响应式网页设计
- ORA-16179 粗心导致的小错误
- hdu4638(离线算法+线段树)
- POJ 1298
- html4学习笔札
- [处男作]SpriteSheetViewer 动画查看器V1.0发布!
- 利用闪回query 恢复删除的数据及存储过程
- 策略模式-鸭子的变化
- 如何收集EBS SOA Log
- 合成析构函数与虚析构函数
- The Role of Delegation Tokens in Apache Hadoop Security
- 零下一度的青春