By Koios
Wordle 是一款猜字遊戲
每次輸入一個猜測,答案會依據猜測的每個字給予結果
題目要我們模擬 Wordle 判斷每次猜測的結果的顏色標記
第一行輸入答案字串,長度介在 \(4\)~\(10\)
第二行開始每行會是猜測字串,長度與答案字串相同
猜測字串輸入到跟答案字串相同時結束
題目保證猜測字串當中不會有重複出現的字母
對於每個猜測字串,輸出一行相對應顏色
對猜測字串的每個字母\(c\)判斷
如果\(c\)放在正確位置,標記為綠色(A)
否則尋找答案當中是否存在\(c\) 有則標記黃色(B),否則標記灰色(C)
#include<iostream>
#include<cstring>
using namespace std;
int main(){
char answer[15], guess[15], color[15];
cin>>answer;
size_t len = strlen(answer);
do{
cin>>guess;
for(int i=0 ; i<len ; i++){
if(guess[i] == answer[i]){
color[i] = 'A';
}
else{
bool found = false;
for(int j=0 ; j<len && !found ; j++){
if(guess[i] == answer[j]){
color[i] = 'B';
found = true;
}
}
if(!found){
color[i] = 'C';
}
}
}
color[len] = '\0';
cout<<color<<'\n';
}while(strcmp(guess, answer) != 0);
return 0;
}#include<iostream>
#include<cstring>
using namespace std;
int main(){
char answer[15], guess[15], color[15];
cin>>answer;
size_t len = strlen(answer);
do{
cin>>guess;
for(int i=0 ; i<len ; i++){
if(guess[i] == answer[i]){
color[i] = 'A';
}
else{
bool found = false;
for(int j=0 ; j<len && !found ; j++){
if(guess[i] == answer[j]){
color[i] = 'B';
found = true;
}
}
if(!found){
color[i] = 'C';
}
}
}
color[len] = '\0';
cout<<color<<'\n';
}while(strcmp(guess, answer) != 0);
return 0;
}#include<iostream>
#include<cstring>
using namespace std;
int main(){
char answer[15], guess[15], color[15];
cin>>answer;
size_t len = strlen(answer);
do{
cin>>guess;
for(int i=0 ; i<len ; i++){
if(guess[i] == answer[i]){
color[i] = 'A';
}
else{
bool found = false;
for(int j=0 ; j<len && !found ; j++){
if(guess[i] == answer[j]){
color[i] = 'B';
found = true;
}
}
if(!found){
color[i] = 'C';
}
}
}
color[len] = '\0';
cout<<color<<'\n';
}while(strcmp(guess, answer) != 0);
return 0;
}#include<iostream>
#include<cstring>
using namespace std;
int main(){
char answer[15], guess[15], color[15];
cin>>answer;
size_t len = strlen(answer);
do{
cin>>guess;
for(int i=0 ; i<len ; i++){
if(guess[i] == answer[i]){
color[i] = 'A';
}
else{
bool found = false;
for(int j=0 ; j<len && !found ; j++){
if(guess[i] == answer[j]){
color[i] = 'B';
found = true;
}
}
if(!found){
color[i] = 'C';
}
}
}
color[len] = '\0';
cout<<color<<'\n';
}while(strcmp(guess, answer) != 0);
return 0;
}#include<iostream>
#include<cstring>
using namespace std;
int main(){
char answer[15], guess[15], color[15];
cin>>answer;
size_t len = strlen(answer);
do{
cin>>guess;
for(int i=0 ; i<len ; i++){
if(guess[i] == answer[i]){
color[i] = 'A';
}
else{
bool found = false;
for(int j=0 ; j<len && !found ; j++){
if(guess[i] == answer[j]){
color[i] = 'B';
found = true;
}
}
if(!found){
color[i] = 'C';
}
}
}
color[len] = '\0';
cout<<color<<'\n';
}while(strcmp(guess, answer) != 0);
return 0;
}#include<iostream>
#include<cstring>
using namespace std;
int main(){
char answer[15], guess[15], color[15];
cin>>answer;
size_t len = strlen(answer);
do{
cin>>guess;
for(int i=0 ; i<len ; i++){
if(guess[i] == answer[i]){
color[i] = 'A';
}
else{
bool found = false;
for(int j=0 ; j<len && !found ; j++){
if(guess[i] == answer[j]){
color[i] = 'B';
found = true;
}
}
if(!found){
color[i] = 'C';
}
}
}
color[len] = '\0';
cout<<color<<'\n';
}while(strcmp(guess, answer) != 0);
return 0;
}維吉尼亞密碼是一種加密方式,其中有
透過表格可以將 \(p\) 與 \(k\) 對應到 \(c\)
題目希望我們將\(c\)當中每個字母出現的次數輸出
輸入總共兩行
輸出一行(不換行),包含 \(26\) 個數字表示字母出現次數
實際上就是位移數量不定的凱薩加密
令 \(c_i\) 表示密文第 \(i\) 個字元是第幾個字母
令 \(p_i\) 表示明文第 \(i\) 個字元是第幾個字母
令 \(k_i\) 表示金鑰第 \(i\) 個字元是第幾個字母
$$c_i = (p_i + k_i) \% 26$$
#include<iostream>
#include<cstring>
using namespace std;
int main(){
char PlainText[1005], Key[1005], CipherText[1005];
cin>>PlainText>>Key;
size_t len = strlen(PlainText);
int Counter[26];
for(int i=0 ; i<26 ; i++){
Counter[i] = 0;
}
for(int i=0 ; i<len ; i++){
CipherText[i] = 'a' + ((PlainText[i] - 'a') + (Key[i] - 'a')) % 26;
Counter[CipherText[i] - 'a']++;
}
for(int i=0 ; i<26 ; i++){
if(i > 0){
cout<<' ';
}
cout<<Counter[i];
}
return 0;
}#include<iostream>
#include<cstring>
using namespace std;
int main(){
char PlainText[1005], Key[1005], CipherText[1005];
cin>>PlainText>>Key;
size_t len = strlen(PlainText);
int Counter[26];
for(int i=0 ; i<26 ; i++){
Counter[i] = 0;
}
for(int i=0 ; i<len ; i++){
CipherText[i] = 'a' + ((PlainText[i] - 'a') + (Key[i] - 'a')) % 26;
Counter[CipherText[i] - 'a']++;
}
for(int i=0 ; i<26 ; i++){
if(i > 0){
cout<<' ';
}
cout<<Counter[i];
}
return 0;
}#include<iostream>
#include<cstring>
using namespace std;
int main(){
char PlainText[1005], Key[1005], CipherText[1005];
cin>>PlainText>>Key;
size_t len = strlen(PlainText);
int Counter[26];
for(int i=0 ; i<26 ; i++){
Counter[i] = 0;
}
for(int i=0 ; i<len ; i++){
CipherText[i] = 'a' + ((PlainText[i] - 'a') + (Key[i] - 'a')) % 26;
Counter[CipherText[i] - 'a']++;
}
for(int i=0 ; i<26 ; i++){
if(i > 0){
cout<<' ';
}
cout<<Counter[i];
}
return 0;
}#include<iostream>
#include<cstring>
using namespace std;
int main(){
char PlainText[1005], Key[1005], CipherText[1005];
cin>>PlainText>>Key;
size_t len = strlen(PlainText);
int Counter[26];
for(int i=0 ; i<26 ; i++){
Counter[i] = 0;
}
for(int i=0 ; i<len ; i++){
CipherText[i] = 'a' + ((PlainText[i] - 'a') + (Key[i] - 'a')) % 26;
Counter[CipherText[i] - 'a']++;
}
for(int i=0 ; i<26 ; i++){
if(i > 0){
cout<<' ';
}
cout<<Counter[i];
}
return 0;
}