UVa

#UVa:10082 – WERTYU

解法指引

先把鍵盤打成一個陣列,這樣比較好得解。

程式碼(C++:0.012)

10082.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*******************************************************/
/* UVa 10082 WERTYU                                    */
/* Author: LanyiKnight [at] knightzone.org             */
/* Version: 2012/03/23                                 */
/*******************************************************/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
  
int main(){
  const char keyboard[] = "   `1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
  const int kblen = strlen(keyboard);
  char hash[256];
  string s;
   
  for( int i = 2 ; i < kblen ; i++ )
    hash[keyboard[i]] = keyboard[i-1];
   
  while( getline( cin, s ) ){
    for( int i = 0 ; i < s.length() ; i++ )
      printf( "%c", hash[s[i]] );
    printf( "\n" );
  }
  return 0;
}

#UVa:272 – TEX Quotes

解法指引

照著題目要求,更換雙引號即可。

程式碼(C++:0.016)

272.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*******************************************************/
/* UVa 272 TEX Quotes                                  */
/* Author: LanyiKnight [at] knightzone.org             */
/* Version: 2011/11/24                                 */
/*******************************************************/
#include<iostream>
#include<cstdio>
using namespace std;
 
int main(){
  string s;
  bool leftorright = 0;
  while( getline( cin, s ) )
  {
    for( int i = 0 ; i < s.length() ; i++ )
      if( s[i] == '"' ){
        if( leftorright )
          printf( "''" );
        else
          printf( "``" );
        leftorright ^= 1;
      }
      else{
        printf( "%c", s[i] );
      }
    printf( "\n" );
  }
  return 0;
}