46 条题解
-
0201060134wh LV 8 @ 2015-11-15 18:39:11
#include<stdio.h>
#include<string.h>
char a[105];
char b[1005];
char qw(char y,char z)
{
char x,t;
if(y>='a'&&y<='z')
{
t='a';
}else
{
t='A';
}
for(x='A';x<='Z';x++)
{
if(z==(x+y-'A'-t)%26+'A')
{
printf("%c",x);
return 1;
}
}
for(x='a';x<='z';x++)
{
if(z==(x+y-'a'-t)%26+'a')
{
printf("%c",x);
return 1;
}
}
}int main()
{
gets(a);
gets(b);
int la=strlen(a);
int lb=strlen(b);
for(int i=0;i<=lb;i++)
{
int k1=a[i%la],c1=b[i];
qw(k1,c1);
}
} -
02015-10-24 22:35:21@
用时最短的程序了
-
02015-10-24 22:34:23@
评测状态 Accepted
题目 P1778 vigenere密码
递交时间 2015-10-24 22:30:55
代码语言 Pascal
评测机 VijosEx
消耗时间 3 ms
消耗内存 772 KiB
评测时间 2015-10-24 22:30:57
评测结果
编译成功Free Pascal Compiler version 2.6.4 [2014/03/06] for i386
Copyright (c) 1993-2014 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling foo.pas
foo.pas(3,15) Note: Local variable "ls" not used
Linking foo.exe
19 lines compiled, 0.0 sec , 27280 bytes code, 1628 bytes data
1 note(s) issued
测试数据 #0: Accepted, time = 0 ms, mem = 712 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 708 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 772 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 708 KiB, score = 10
测试数据 #4: Accepted, time = 1 ms, mem = 772 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 772 KiB, score = 10
测试数据 #6: Accepted, time = 1 ms, mem = 772 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 772 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 772 KiB, score = 10
测试数据 #9: Accepted, time = 1 ms, mem = 772 KiB, score = 10
Accepted, time = 3 ms, mem = 772 KiB, score = 100
代码
var k:string;
s:char;
kk,i,j,lk,ls,t:integer;
begin
readln(k);lk:=length(k);
for i:=0 to lk do
k[i]:=upcase(k[i]);
kk:=0;
while not eof do
begin
read(s);
if (s<'A')or((s>'Z')and(s<'a'))or(s>'z') then halt;
inc(kk);
if kk>lk then kk:=kk mod lk;
if s<='Z' then j:=65 else j:=97;
t:=ord(s)-ord(k[kk])+65;
if t<j then t:=t+26;
write(chr(t));
end;
end. -
02015-10-16 21:27:22@
记录信息
评测状态 Accepted
题目 P1778 vigenere密码
递交时间 2015-10-16 21:26:47
代码语言 C++
评测机 VijosEx
消耗时间 45 ms
消耗内存 528 KiB
评测时间 2015-10-16 21:26:48
评测结果
编译成功测试数据 #0: Accepted, time = 0 ms, mem = 456 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 460 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 460 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 528 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 528 KiB, score = 10
测试数据 #5: Accepted, time = 15 ms, mem = 528 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 524 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 524 KiB, score = 10
测试数据 #8: Accepted, time = 15 ms, mem = 528 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 528 KiB, score = 10
Accepted, time = 45 ms, mem = 528 KiB, score = 100
代码
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;char s[100];
char k[1000];int flag;
char make(char a,char b)
{
if(flag==0)
return ((b+26-'a')-a+'a')%26+'a';
return ((b+26-'a')-a+'a')%26+'A';
}
int main()
{
scanf("%s",s);
scanf("%s",k);
int len=strlen(k)-1;
int lim=strlen(s);
for(int i=0;i<lim;i++){
if(s[i]<='Z'&&s[i]>='A'){
s[i]=s[i]-'A'+'a';
}
}
for(int i=0;i<=len;i++){
flag=0;
if(k[i]<='Z'&&k[i]>='A'){
flag=1;
k[i]=k[i]-'A'+'a';
}
printf("%c",make(s[i%lim],k[i]));
}return 0;
} -
02015-09-14 01:13:04@
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;int main()
{
string M;
string k;
cin>>k;
cin>>M;
int x1=M.length();
int x2=k.length();
int k2[100];
for(int i=0;i<x2;++i)
{
if( k[i]>='A'&&k[i]<='Z' )
{
k2[i]=k[i]-'A';
}else if( k[i]>='a'&&k[i]<='z' )
{
k2[i]=k[i]-'a';
}
}
for(int i=0;i<x1;++i)
{
int w;
w=M[i]-k2[i%x2];
if(M[i]>=65&&M[i]<=90&&w<65)w=91-(65-w);
else if(M[i]>=97&&M[i]<=122&&w<97)w=123-(97-w);
printf("%c",w);
}
return 0;
} -
02015-08-15 16:15:56@
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;char a[110], b[1010];
int cha = 'a' - 'A';char solve(char x, char y){
bool flag = 0;
if(y < 'a'){
y += cha;
flag = 1;
}
char z = y - x + 'a';
while(z < 'a')
z += 26;
if(flag)
return z - cha;
else
return z;
}int main()
{
cin>>a;
cin>>b;
int len = strlen(a);
for(int i=0; i<len; i++)
if(a[i] < 'a')
a[i] += 'a'-'A';
for(int i=0; i<strlen(b); i++){
char c = solve(a[i%len], b[i]);
printf("%c", c);
}
return 0;
}
模拟。。。 -
02015-08-12 12:25:02@
program vigenere;
var
c,k:ansistring;
nc,nk,i,j,a:integer;
ch:char;
begin
{assign(input,'vigenere.in');
assign(output,'vigenere.out');
reset(input);
rewrite(output);}
readln(k);
nk:=length(k);
for i:=1 to nk do
if ord(k[i])<ord('a') then
k[i]:=chr(ord(k[i])+32);
readln(c);
nc:=length(c);
j:=1;
for i:=1 to nc do
begin
if ord(c[i])>=ord('a') then
begin
if ord(c[i])<ord(k[j]) then
begin
//a:=0;
a:=ord(c[i])-ord('a')+ord('z')+1;
a:=a-ord(k[j])+ord('a');
end
else a:=ord(c[i])-ord(k[j])+ord('a');
end
else begin
if ord(c[i])<(ord(k[j])-32) then
begin
//a:=0;
a:=ord(c[i])-ord('A')+ord('Z')+1;
a:=a-ord(k[j])+ord('a');
end
else a:=ord(c[i])-ord(k[j])+ord('a');
end;
ch:=chr(a);
write(ch);
inc(j);
if j>nk then
j:=j-nk;
end;
writeln;
{close(input);
close(output);}
end.
送给所有像我一样的pascal蒟蒻 -
02015-01-13 17:52:40@
诶,原来拿去搞加密了- -我的天- -
总之注意要用ansistring,我测试的时候是string交的时候忘记改回去了,就过一个点也是醉了。。。
总之大小写可以另外考虑,这题没什么简单办法,字符串的题目都很绕,别把自己圈进去了。写题目前最好把主要公式先写好。
###blcok code
program P1778;
var k,s,ans:ansistring;
lenk,lens,num,i,sum:longint;
down:array[1..1000] of boolean; //记录是否需要把该字符转回小写
begin
//assign(input,'readin.in'); reset(input);
fillchar(down,sizeof(down),false);
readln(k); readln(s); lenk:=length(k); lens:=length(s); num:=0; sum:=0;
k:=upcase(k);
for i:=1 to lens do //是否是小写,同时转成大写方便计算,虽然麻烦,但数据只有1000,时间可不计
if ord(s[i])>ord('Z') then
begin
down[i]:=true; s[i]:=chr(ord(s[i])-32);
end;for i:=1 to lens do //处理
begin
inc(num); if num>lenk then num:=1;
sum:=ord(k[num])-ord('A'); //需要偏移的位数
sum:=ord(s[i])-sum; //偏移后的asc码
if sum<65 then //若小于A要环形结构,+上26
sum:=sum+26;
ans:=ans+chr(sum); //记录,也可以直接判断输出
end;for i:=1 to lens do //处理答案,输出,可以和上步结合。
begin
if down[i]=true then
write(chr(ord(ans[i])+32))
else
write(ans[i]);
end;//close(input);
end. -
02015-01-12 17:56:06@
shit 我的pascal的upcase用不了,什么破玩意,次奥!
怪不得一直都错,我原来把程序做成给加密用的了- -妈呀。下次要好好看题目
-
02014-10-26 15:47:18@
朴素算法
#include <iostream>
#include <cctype>
#include <string>
using namespace std;
char k[27][27];int main()
{
for(int i=0;i<=25;i++)
for(int j=0;j<=25;j++)
{
k[i][j]='A'+(i+j)%26;
}
string key ;
cin>>key;
for(int i=0;i<key.length();i++)
{
key.at(i)=toupper(key.at(i));
}string password,origin ;
cin>>password;
origin = password;for(int i=0;i<password.length();i++)
{
password.at(i)=toupper(password.at(i));
}
int curinkey = 0;
for(int i=0;i<password.length();i++)
{
for(int j=0;j<26;j++)
{
if(k[key.at(curinkey%(key.length()))-'A'][j]==(password.at(i)))
{
curinkey++;
if(isupper(origin.at(i)))
{
cout<<(char)(j+'A');
break;
}
else
{
cout<<(char)(j+'a');
break;}
}
}
}
return 0;
} -
02014-10-24 15:12:52@
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<cstring>
#include<cctype>
#include<ctime>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
char key[101];
char k[1001],uk[1001];
bool uka[1001];
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
gets(key);
gets(uk);
int keyl=strlen(key);
int ukl=strlen(uk);
for(int i=0;i<keyl;i++)
if(key[i]>='a')
key[i]=key[i]-'a';
else
key[i]=key[i]-'A';
for(int i=0;i<ukl;i++)
{
char tmp;
if(uk[i]>='a')
{
uk[i]=uk[i]-'a';
tmp='a';
}
else
{
uk[i]=uk[i]-'A';
tmp='A';
}
if(key[i%keyl]<=uk[i])
k[i]=uk[i]-key[i%keyl]+tmp;
else
k[i]=26+uk[i]-key[i%keyl]+tmp;
printf("%c",k[i]);
}
return 0;
} -
02014-08-24 14:23:56@
测试数据 #0: Accepted, time = 0 ms, mem = 468 KiB, score = 10
测试数据 #1: Accepted, time = 15 ms, mem = 468 KiB, score = 10
测试数据 #2: Accepted, time = 7 ms, mem = 472 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 472 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 472 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 468 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 476 KiB, score = 10
测试数据 #7: Accepted, time = 15 ms, mem = 472 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 468 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 468 KiB, score = 10
Accepted, time = 37 ms, mem = 476 KiB, score = 100
代码
#include<iostream>
#include<cstring>
using namespace std;
string a,b;
char pd(char x,char y)
{
if(x>='a'&&x<='z'&&y>='a'&&y<='z')
{
y-=(x-'a');
if(y<'a')
y+=26;
}
if(x>='a'&&x<='z'&&y>='A'&&y<='Z')
{
y-=(x-'a');
if(y<'A')
y+=26;
}
if(x>='A'&&x<='Z'&&y>='a'&&y<='z')
{
y-=(x-'A');
if(y<'a')
y+=26;
}
if(x>='A'&&x<='Z'&&y>='A'&&y<='Z')
{
y-=(x-'A');
if(y<'A')
y+=26;
}
return y;
}
int main()
{
int i,j;
cin>>a>>b;
for(i=0,j=0;i<b.size();i++,j++)
{
if(j==a.size())
j=0;
cout<<pd(a[j],b[i]);
}
return 0;
} -
02014-07-22 10:17:16@
###
#include <cstdio>
#include <cstring>const int MAXL = 1000+10;
bool cj;
int cl, kl;
char c[MAXL], k[MAXL], an;int main(){
gets(k), gets(c);
kl = strlen(k), cl = strlen(c);
for (int i=0; i<kl; i++)
if (k[i]<97) k[i] += 32;for (int i=0; i<cl; i++){
if (c[i]<97) c[i] += 32, cj = true;
else cj = false;
an = (c[i]-'a'-(k[i%kl]-'a')+26)%26+'a';
if (cj) an -= 32;
printf("%c", an);
}
} -
02014-01-01 12:01:55@
Vijos 题解:http://hi.baidu.com/umule/item/2c997f8ed9600fdae596e017
有疑问请留言 共同进步 -
02013-11-03 17:33:05@
C语言
#include<stdio.h>
int main()
{
char y[100],a[1000];
int i,q,p,x;
scanf("%s%s",&y,&a);
for(i=0;i<=100;i++)
{
if(y[i]==0)
break;
}
for(p=0;p<=1000;p++)
{
if(a[p]==0)
break;
q=p%i;
if(y[q]>='a'&&y[q]<='z')
{
if((a[p]>='a'&&a[p]<='z'&&a[p]-y[q]+97<'a')||(a[p]>='A'&&a[p]<='Z'&&a[p]-y[q]+97<'A'))
x=a[p]-y[q]+97+26;
else
x=a[p]-y[q]+97;
}
else if(y[q]>='A'&&y[q]<='Z')
{
if((a[p]>='a'&&a[p]<='z'&&a[p]-y[q]+65<'a')||(a[p]>='A'&&a[p]<='Z'&&a[p]-y[q]+65<'A'))
x=a[p]-y[q]+65+26;
else
x=a[p]-y[q]+65;
}
printf("%c",x);
}
return 0;
} -
02013-10-27 22:49:17@
var fin:text;
i,j,k:longint;
old,new,key:ansistring;
lenk,lend:longint;
add:array[0..1001] of byte;
begin
readln(key);
readln(old);
lend:=length(old);
lenk:=length(key);
fillchar(add,sizeof(add),0);
for i:=1 to lend do if ord(old[i])>96 then add[i]:=32;
key:=upcase(key);
old:=upcase(old);
for i:=1 to lend do begin
k:=(i-1) mod lenk+1;
if old[i]<key[k] then write(chr(ord(old[i])+91-ord(key[k])+add[i]))
else write(chr(ord(old[i])-ord(key[k])+65+add[i]));
end;
end. -
02013-10-21 14:38:05@
直接模拟找
var i,j,k,n,m,l,h:longint;
key:string;
s:ansistring;
a:array[0..26,0..26]of integer;
procedure init;
begin
for i:=1 to 26 do
a[1,i]:=i;
for i:=2 to 26 do
for j:=1 to 26 doif (a[i-1,j]+1)mod 26 =0 then a[i,j]:=26 else a[i,j]:=(a[i-1,j]+1)mod 26;
end;procedure readlq;
begin
readln(key);
read(s);
key:=upcase(key);
m:=length(key);
n:=length(s);
end;
procedure writel;
begin
for i:=1 to n do
begin
if (i mod m)=0 then j:=m else j:=(i mod m);
case s[i] of
'A'..'Z': for l:=1 to 26 do for k:=1 to 26 do if (s[i]=chr(a[l,k]+64)) and (key[j]=chr(k+64))then write(chr(l+64));
'a'..'z': for l:=1 to 26 do for k:=1 to 26 do if (s[i]=chr(a[l,k]+96)) and (key[j]=chr(k+64))then write(chr(l+96));
end;
end;
end;begin
readlq;
init;writel;
end. -
02013-10-19 08:33:27@
这道题和原题不一样,太不一样了,建议去洛谷看原题
-
02013-10-08 13:58:27@
编译成功
测试数据 #0: Accepted, time = 0 ms, mem = 1028 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 1068 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 1032 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 1032 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 1032 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 1028 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 1068 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 1028 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 1028 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 804 KiB, score = 10
Accepted, time = 0 ms, mem = 1068 KiB, score = 100
代码
var
u:array[0..1001] of integer; c:ansistring; k:string;
l,i,j,d:integer;
begin
readln(k); readln(c); l:=length(c);
for i:=1 to l do if ord(c[i])>96 then u[i]:=32;
j:=length(k); k:=upcase(k); c:=upcase(c);
for i:=1 to l do begin
d:=(i-1) mod j+1;
if c[i]<k[d] then write(chr(ord(c[i])+91-ord(k[d])+u[i]))
else write(chr(ord(c[i])+65-ord(k[d])+u[i]));
end;
end. -
02013-10-08 13:56:54@
var
u:array[0..1001] of integer; c:ansistring; k:string;
l,i,j,d:integer;
begin
readln(k); readln(c); l:=length(c);
for i:=1 to l do if ord(c[i])>96 then u[i]:=32;
j:=length(k); k:=upcase(k); c:=upcase(c);
for i:=1 to l do begin
d:=(i-1) mod j+1;
if c[i]<k[d] then write(chr(ord(c[i])+91-ord(k[d])+u[i]))
else write(chr(ord(c[i])+65-ord(k[d])+u[i]));
end;
end.