标签:blank 模拟 space eve bsp cli ios 循环 scan
因为是循环的,所以我们进行%26即可
#include <iostream> #include <cstdio> using namespace std; const int Mod = 26; const char e[Mod] = {‘a‘,‘b‘,‘c‘,‘d‘,‘e‘,‘f‘,‘g‘,‘h‘,‘i‘,‘j‘,‘k‘,‘l‘,‘m‘,‘n‘,‘o‘,‘p‘,‘q‘,‘r‘,‘s‘,‘t‘,‘u‘,‘v‘,‘w‘,‘x‘,‘y‘,‘z‘}; int n; string y; int main() { scanf("%d",&n); cin>>y; int len=y.length(); for(int i=0,d; i<len; i++) { d=(y[i]-‘a‘+n)%26; printf("%c",e[d]); } return 0; }
(Maybe是Here。。)
将字符串转化为数字之后,边乘边模即可
注意ret的初始值应该设置为1,而不是0,因为用到了乘
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int Mod = 47; char s[10],p[10]; int UFO(char a[],int len) { int ret=1; for(int i=0,x; i<len; i++) { x=a[i]-‘A‘+1; ret=ret*x%Mod; } return ret; } int main() { cin>>s>>p; int lens=strlen(s),lenp=strlen(p); if(UFO(s,lens)==UFO(p,lenp)) printf("GO"); else printf("STAY"); return 0; }
标签:blank 模拟 space eve bsp cli ios 循环 scan
原文地址:http://www.cnblogs.com/zxqxwnngztxx/p/7787719.html