zoj 1884 || poj 2538 WERTYU(这水让我很YM!)

输出键盘字符前的那个字符。

 

开始想,难不能我要用N个case of? = =

 

后来想通了,把键盘上字符都按顺序存到字符串数组里。。。

 

少存了 - = WA了数次 !

 

我了个去!!

 

学习了一点,scanf可以吃控制字符(空格回车tab等等)。。。 cin不吃。。。

 

还有str数组里的/,得写俩。。。要不有警告。。。

 

#include <stdio.h> #include <stdlib.h> #include <iostream> #include <string.h> using namespace std; int main(void) { char ch; char str[] = {"`1234567890-=QWERTYUIOP[]//ASDFGHJKL;'ZXCVBNM,./"}; char text[10000]; int len = strlen(str); while( gets(text) ) { for(int k=0; k<strlen(text); k++) { if( text[k] == ' ' ) cout << text[k]; for(int i=0; i<len; i++) { if( text[k] == str[i] ) cout << str[i-1] ; } } cout << endl; } return 0; }  

你可能感兴趣的:(zoj 1884 || poj 2538 WERTYU(这水让我很YM!))