利用ASCII碼找出Sample Input和Sample Output相差的k值,將輸入的每個字都以此k值做加減即可得解。
C++(0.172)
/*******************************************************/ /* UVa 458 The Decoder */ /* Author: LanyiKnight [at] knightzone.org */ /* Version: 2011/11/25 */ /*******************************************************/ #include<iostream> #include<cstdio> using namespace std; int main(){ const int K = (int)('*'-'1'); string s; while( getline( cin, s ) ){ for( int i = 0 ; i < s.length() ; i++ ) printf( "%c", s[i]+K ); printf( "\n" ); } return 0; }