辽宁师范大学 • 张大为@https://daweizh.github.io/noip/
#include <iostream> #include <cstring> using namespace std; int main(){ char cs[300]; cin.getline(cs,300); int len = strlen(cs); int sum = 0; for(int i=0;i<len;i++) if(cs[i]>='0' && cs[i]<='9') sum = sum + 1; cout << sum << endl; return 0; }
/* example 1: abcabcdefabcd abcdef 333211 abcabcdefabcd 33333321 steps: step1: read string into memory step2: count number of each character step3: find first character of number one step4: output answer */ #include <iostream> using namespace std; int count[26]; int main(){ char txt[100005]; int ntxt=0,flag=0; while((txt[ntxt]=getchar())!='\n'){ count[txt[ntxt]-'a'] = count[txt[ntxt]-'a']+1; ntxt++; } for(int i=0;i<ntxt;i++) if(count[txt[i]-'a']==1){ cout << txt[i] << endl; flag=1; break; } if(!flag){ cout << "no" << endl; } return 0; }
#include <iostream> #include <cstring> using namespace std; int main(){ double h,count=0.0; char a[500]; char b[500]; cin >> h; cin >> a; cin >> b; int len = strlen(a); for(int i=0;i<len;i++){ if(a[i]==b[i]){ count = count + 1; } } if(count/len>h) cout << "yes" << endl; else cout << "no" << endl; return 0; }
#include <iostream> using namespace std; int p(char a){ return (int)a; } int main(){ int n; char s1[10],s2[10]; cin >> n; for(int i=0;i<n;i++){ cin >> s1 >> s2 ; if(p(s1[0])==p(s2[0])){ cout << "Tie" << endl; }else{ if(p(s1[0])==80){ //player1==Paper if(p(s2[0])==82) //player2=Rock cout << "Player1" << endl; else //player2=Scissors cout << "Player2" << endl; }else if(p(s1[0])==82){ //player1=Rock if(p(s2[0])==80) //player2=paper cout << "Player2" << endl; else //player2=Scissors cout << "Player1" << endl; }else{ //player1=Scissors if(p(s2[0])==80) //player2=paper cout << "Player1" << endl; else //player2=rock cout << "Player2" << endl; } } } return 0; }
#include <iostream> using namespace std; string s; int main(){ getline(cin,s); for(int i=0;i<s.size()-1;i++){ cout << char(s[i]+s[i+1]); } cout << char(s[0]+s[s.size()-1]) << endl; return 0; }
#include <iostream> using namespace std; int main(){ string s; getline(cin,s); int i=0; for(;i<s.size();i++){ if(s[0]>='0' && s[0]<='9'){ break; } if(s[i]=='_' || (s[i]>='0' && s[i]<='9') || (s[i]>='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z')) continue; else break; } if(i==s.size()){ cout << "yes" << endl; }else{ cout << "no" << endl; } return 0; }
#include <iostream> using namespace std; int main(){ string s; getline(cin,s); for(int i=0;i<s.size();i++){ switch(s[i]){ case 'A':cout << 'T';break; case 'T':cout << 'A';break; case 'G':cout << 'C';break; case 'C':cout << 'G';break; } } return 0; }
#include <iostream> #include <cstring> using namespace std; char str[40],src,dst; int main(){ cin >> str >> src >> dst; int len = strlen(str); for(int i=0;i<len;i++){ if(str[i]==src){ str[i] = dst; } } for(int i=0;i<len;i++){ cout << str[i]; } cout << endl; return 0; }
#include <iostream> using namespace std; int main(){ string s; getline(cin,s); for(int i=0;i<s.size();i++){ if(s[i]>='a' && s[i]<='z'){ s[i] = 'a' + (s[i]-'a' +1) % 26; } if(s[i]>='A' && s[i]<='Z'){ s[i] = 'A' + (s[i]-'A' +1) % 26; } } cout << s << endl; return 0; }
#include <iostream> using namespace std; int main(){ int tmp; string s; getline(cin,s); for(int i=0;i<s.size();i++){ if(s[i]>='A' && s[i]<='Z'){ tmp = s[i]-5; if(tmp < 65) s[i]='Z'+tmp-64; else s[i] = tmp; } } cout << s << endl; return 0; }
#include <iostream> #include <cstring> using namespace std; char inf[105],src[105],dst[105]; int book[300],num[300],inflen,srclen,dstlen; bool flag=true; int main(){ scanf("%s",inf); scanf("%s",src); scanf("%s",dst); inflen = strlen(inf); srclen = strlen(src); dstlen = strlen(dst); for(int i=0;i<inflen;i++){ if(book[inf[i]]==0 && src[i]!=0){ book[inf[i]]=src[i]; }else if(book[inf[i]]!=src[i]){ flag=false; } } if(flag){ for(int i=65;i<=90;i++){ if(book[i]==0){ flag=false; break; } } } for(int i=0;i<srclen;i++){ if(num[src[i]]==0 && inf[i]!=0){ num[src[i]]=inf[i]; }else if(num[src[i]]!=inf[i]){ flag = false; } } if(flag){ for(int i=65;i<=90;i++){ if(num[i]==0){ flag=false; break; } } } if(flag){ for(int i=0;i<dstlen;i++){ cout << char(book[dst[i]]); } cout << endl; }else{ cout << "Failed" << endl; } return 0; }
#include <iostream> #include <cstring> using namespace std; char src[100],dst[100]; int main(){ cin >> src; int len = strlen(src); for(int i=0;i<len;i++){ char c = src[len-i-1]; if(c>='A' && c<='Z'){ c = c + 35; if(c>'z') c = 'a' + (c-'z'-1); } else if(c>='a' && c<='z'){ c = c - 29; if(c>'Z') c = 'A' + (c-'Z'-1); } dst[i] = c; } cout << dst << endl; return 0; }
#include <iostream> #include <cstring> using namespace std; char s[105]; int main(){ gets(s); int len = strlen(s); for(int i=0;i<len;i++){ if(s[i]>='a' && s[i]<='z') s[i]=s[i]-32; } cout << s << endl; return 0; }
#include <iostream> #include <cstring> using namespace std; char s[90]; int main(){ gets(s); int len = strlen(s); for(int i=0;i<len;i++){ if(int(s[i])>=65 && int(s[i])<=90) cout << char(s[i]+32); else if(int(s[i])>=97 && int(s[i])<=122) cout << char(s[i]-32); else cout << s[i]; } cout << endl; return 0; }
#include <iostream> #include <cstring> using namespace std; int n,len; char s[100]; int main(){ cin >> n; getchar(); for(int i=0;i<n;i++){ gets(s); len = strlen(s); if(s[0]>='a' && s[0]<='z') s[0]=s[0]-32; for(int j=1;j<len;j++){ if(s[j]>='A' && s[j]<='Z') s[j]=s[j]+32; } cout << s << endl; } return 0; }
#include <iostream> #include <cstring> using namespace std; char src[100],dst[100]; int ls,ld,i; void toUp(char * a){ int len= strlen(a); for(int i=0;i<len;i++){ if(a[i]>='a' && a[i]<='z') a[i]=a[i]-32; } } int main(){ gets(src); toUp(src); gets(dst); toUp(dst); ls = strlen(src); ld = strlen(dst); int len = ls < ld ? ls:ld; for(i=0;i<len;i++){ if(src[i]>dst[i]){ cout <<">" << endl; break; }else if(src[i]<dst[i]){ cout << "<" << endl; break; } } if(i==len){ if(ls==ld){ cout << "=" << endl; }else{ char c = ls<ld?'<':'>'; cout << c << endl; } } return 0; }
#include <iostream> #include <string> using namespace std; string src1,src2,dst1,dst2; string filt(string s){ string tmp = ""; int len = s.length(); for(int i=0;i<len;i++){ if(s[i]!=' ') if(s[i]>='a' && s[i]<='z') tmp = tmp + char(s[i]-32); else tmp = tmp + s[i]; } return tmp; } int main(){ getline(cin,src1); getline(cin,src2); dst1 = filt(src1); dst2 = filt(src2); if(dst1.compare(dst2)==0){ cout << "YES" << endl; }else{ cout << "NO" << endl; } return 0; }
#include <iostream> #include <string> using namespace std; string s1,s2; int main(){ getline(cin,s1); getline(cin,s2); string::size_type idx1,idx2; idx1 = s1.find(s2); idx2 = s2.find(s1); if(idx1==string::npos && idx2==string::npos){ cout << "No substring" << endl; }else if(idx1==string::npos){ cout << s1 <<" is substring of " << s2 << endl; }else{ cout << s2 <<" is substring of " << s1 << endl; } return 0; }
#include <iostream> #include <string> using namespace std; string s1,s2,d1,d2; int main(){ cin >> s1 >> s2; d1 = s1+s1; d2 = s2+s2; if(d1.find(s2)!=-1 && s2.size()<=s1.size()){ cout << "true" << endl; }else if(d2.find(s1)!=-1 && s1.size()<=s2.size()){ cout << "true" << endl; }else{ cout << "false" << endl; } return 0; }
#include <iostream> #include <cstring> using namespace std; char post[3][5]={"er","ly","ing"},s[50]; int main(){ cin >> s; int l = strlen(s); for(int i=0;i<3;i++){ int len = strlen(post[i]),j; for(j=0;j<len;j++){ if(post[i][len-j-1]!=s[l-j-1]) break; } if(j==len){ s[l-j] = '\0'; break; } } cout << s << endl; return 0; }
#include <iostream> #include <string> using namespace std; string st[100],src,dst; int n=0; int main(){ while(cin >> st[n++]); src = st[n-3]; dst = st[n-2]; n=n-3; for(int i=0;i<n;i++){ if(st[i].compare(src)==0){ st[i] = dst; } } cout << st[0]; for(int i=1;i<n;i++) cout << " " << st[i]; cout << endl; return 0; }
#include <iostream> #include <string> using namespace std; string email,mail,usr,psw; int n,flag=1; int main(){ cin >> email >> n; for(int i=0;i<n;i++){ cin >> usr >> psw >> mail; if(email.compare(mail)==0){ flag = 0; int len = psw.size(); for(int i=0;i<len;i++){ if(psw[i]>='A' && psw[i]<='Z') psw[i] = psw[i] + 32; else if(psw[i]>='a' && psw[i]<='z') psw[i] = psw[i] - 32; } cout << usr << " " << psw << endl; } } if(flag){ cout << "empty" << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main(){ string s,temp; cin >> s; while(cin >> temp){ s += ' ' + temp; } cout << s << endl; return 0; }
#include <iostream> #include <cstring> using namespace std; char s[1005]; int main(){ scanf("%s",s); cout << strlen(s); while(scanf("%s",s)==1){ cout << "," << strlen(s); } cout << endl; return 0; }
#include <iostream> #include <string> using namespace std; string st[300]; int n=0,mn=100000,mx=0,pmax,pmin; int main(){ while(cin>>st[n]){ int len = st[n].size(); if(st[n][0]==',') st[n].erase(0,1); if(st[n][len-1]==',') st[n].erase(len-1,0); n++; } for(int i=0;i<n;i++){ if(st[i].length()>mx){ mx = st[i].length(); pmax = i; } if(st[i].length()<mn){ mn = st[i].length(); pmin = i; } } cout << st[pmax] << endl; cout << st[pmin] << endl; return 0; }
#include <iostream> #include <string> using namespace std; string s,src,lft,rgt; int len,l,r; int main(){ cin >> s; len = s.length(); l = s.find_first_of(","); r = s.find_last_of(","); src = s.substr(0,l); lft = s.substr(l+1,r-l-1); rgt = s.substr(r+1,len-r-1); l = src.find(lft); r = src.rfind(rgt); if(l==-1 || r ==-1){ cout << -1 << endl; }else{ if(r>=l+lft.length()) cout << r -l -lft.length() << endl; else cout << "-1" << endl; } return 0; }
#include <iostream> #include <cstring> #include <algorithm> using namespace std; char str[505]; int l,r=0; int main(){ gets(str); int len = strlen(str); while(r<len){ while(str[r]==' '&&r<len) r++; l=r; while(str[r]!=' ' && r<len){ r++; } reverse(str+l,str+r); } cout << str << endl; return 0; }
#include <iostream> #include <string> #include <vector> using namespace std; vector<string> vs; string s; int main(){ while(cin>>s){ vs.push_back(s); } int len = vs.size(); cout << vs[len-1]; for(int i=len-2;i>=0;i--) cout << " " << vs[i]; cout << endl; return 0; }
#include <iostream> #include <string> using namespace std; string isbn; int sum = 0,p=1; int main(){ cin >> isbn; sum = 0; for(int i=0;i<11;i++) if(isbn[i]!='-') sum = sum + (isbn[i]-'0')*p++; if((isbn[12]=='X' && sum%11==10) || (isbn[12]-'0'==sum%11)) cout << "Right" << endl; else if(sum%11==10){ isbn[12]='X'; cout << isbn <<endl; }else{ isbn[12] = sum%11+'0'; cout << isbn << endl; } return 0; }
#include <iostream> #include <string> using namespace std; string s1,s2,s; int len,mx=0; int main(){ cin >> s1 >> s2; if(s1.length()>s2.length()){ s = s1; s1= s2; s2 = s; } len = s1.length(); s1 = s1 + s1; s2 = s2 + s2; mx = 0; for(int l=1;l<=len;l++){ for(int i=0;i<=2*len-l;i++){ s = s1.substr(i,l); if(s2.find(s)!=string::npos){ if(s.size()>mx){ mx = s.size(); } } } } cout << mx << endl; return 0; }
#include <iostream> #include <cstring> #include <string> #include <stack> using namespace std; char s[1005],ans[2005],d; int len,cnt,p; string ntos(int a){ stack<char> stk; string t = ""; while(a){ stk.push(char(a%10+48)); a=a/10; } while(!stk.empty()){ t = t + stk.top(); stk.pop(); } return t; } int main(){ cin >> s; len = strlen(s); d=s[0]; cnt = 1; p=0; for(int i=1;i<len;i++){ if(s[i]!=d){ string r = ntos(cnt); for(int j=0;j<r.size();j++){ ans[p++] = r[j]; } ans[p++] = d; cnt=1; d=s[i]; }else{ cnt++; } } string r = ntos(cnt); for(int j=0;j<r.size();j++){ ans[p++] = r[j]; } ans[p++] = d; cout << ans << endl; return 0; }
#include <iostream> #include <cstring> #include <string> #include <stack> using namespace std; char s[1005],ans[2005],d; int len,cnt; void toup(char a[]){ int l = strlen(a); for(int i=0;i<l;i++) if(a[i]>='a' && a[i]<='z') a[i]=a[i]-32; } int main(){ cin >> s; toup(s); len = strlen(s); d=s[0]; cnt = 1; for(int i=1;i<len;i++){ if(s[i]!=d){ cout << "(" << d << "," << cnt << ")"; cnt=1; d=s[i]; }else{ cnt++; } } cout << "(" << d << "," << cnt << ")" << endl; return 0; }
#include <iostream> #include <cstring> using namespace std; char c[105]; int len,flag=1,mid; int main(){ cin >> c ; len = strlen(c); mid = len/2; for(int i=0;i<mid;i++){ if(c[i]!=c[len-i-1]){ flag=0; break; } } if(flag) cout << "yes" << endl; else cout << "no" << endl; return 0; }
#include <iostream> #include <string> using namespace std; string s; int main(){ cin >> s; int len = s.size(),end,right,left; for(int i=2;i<=len;i++){ //枚举子串的长度 end = len - i; for(int begin=0;begin<=end;begin++){ right = begin+i-1; for(left=begin;left<right;left++,right--){ if(s[left]!=s[right]) break; } if(left>=right){ right = begin+i-1; for(left=begin;left<=right;left++) cout << s[left]; cout << endl; } } } return 0; }
#include <iostream> #include <string> using namespace std; int p1,p2,p3; string src,dst=""; char tolower(char c){ if(c>='A' && c<='Z') return c + ('a'-'A'); return c; } char toupper(char c){ if(c>'a' && c<='z') return c + ('A'-'a'); return c; } bool isnumber(char c){ return (c>='0' && c<='9')?1:0; } bool ischar(char c){ return (c>='a' && c <='z' || c >='A' && c <='Z')?1:0; } int main(){ int p=0; cin >> p1 >> p2 >> p3; cin >> src; dst=src[0]; for(int i=1;i<src.size()-1;i++){ if(src[i]=='-'){ if(isnumber(src[i-1]) && isnumber(src[i+1]) || ischar(src[i-1])&&ischar(src[i+1])){ if(src[i+1]>src[i-1]){ if(p3==1){ //顺序 for(char j=src[i-1]+1;j<src[i+1];j++){ for(int k=1;k<=p2;k++){ switch(p1){ case 1: if(isnumber(j)) dst = dst + j; else dst = dst + tolower(j); break; case 2: if(isnumber(j)) dst = dst + j; else dst = dst + toupper(j); break; case 3: dst = dst + '*'; break; } } } }else{ //逆序 for(char j=src[i+1]-1;j>src[i-1];j--){ for(int k=1;k<=p2;k++){ switch(p1){ case 1: if(isnumber(j)) dst = dst + j; else dst = dst + tolower(j); break; case 2: if(isnumber(j)) dst = dst + j; else dst = dst + toupper(j); break; case 3: dst = dst + '*'; break; } } } } }else{ dst = dst + src[i]; } }else{ dst = dst + src[i]; } }else{ dst = dst + src[i]; } } dst = dst + src[src.length()-1]; cout << dst << endl; return 0; }