#include<iostream>usingnamespace std;intmain(){int a, b;cin >> a >> b;string num =to_string(a + b);string ans ="";for(int i = num.size()-1, j =0; i >=0; i --){ans = num[i]+ ans;++ j;if(j %3==0&& i && num[i -1]!='-') ans =","+ ans;}cout << ans;return0;}
1005 Spell It Right (20 分)
題意 :得到輸入數的各位之和后按位輸出分別的英文
語法 :行末無空格,可以先輸出第一位后,分別輸出一個空格加每一位
#include<iostream>usingnamespace std;string word[]={"zero","one","two","three","four","five","six","seven","eight","nine"};intmain(){string n;cin >> n;int s =0;for(auto c : n) s += c -'0';string str =to_string(s);cout << word[str[0]-'0'];for(int i =1; i < str.size(); i ++) cout <<' '<< word[str[i]-'0'];return0;}
1006 Sign In and Sign Out (25 分)
題意 :在輸入的每個第二個字符串中找最小的,第三個找最大的,輸出它們分別對應的第一個字符串
#include<iostream>usingnamespace std;intmain(){string open_id, open_time;string close_id, close_time;int m;cin >> m;for(int i =0; i < m; i ++){string id, in_time, out_time;cin >> id >> in_time >> out_time;// 更新if(!i || in_time < open_time){open_id = id;open_time = in_time;}if(!i || out_time > close_time){close_id = id;close_time = out_time;}}cout << open_id <<' '<< close_id;return0;}
#include<iostream>usingnamespace std;constint N =1010;string name[N], pwd[N];string change(string str){string res;for(auto c : str)if(c =='1') res +='@';elseif(c =='0') res +='%';elseif(c =='l') res +='L';elseif(c =='O') res +='o';else res += c;return res;}intmain(){int n;cin >> n;int m =0;for(int i =0; i < n; i ++){string a, b;cin >> a >> b;string c =change(b);if(b != c) name[m]= a, pwd[m ++]= c;}if(!m){if(n ==1)puts("There is 1 account and no account is modified");elseprintf("There are %d accounts and no account is modified", n);}else{cout << m << endl;for(int i =0; i < m; i ++) cout << name[i]<<' '<< pwd[i]<< endl;}return0;}
#include<iostream>usingnamespace std;string change(string a,int n){int k = a.find('.');if(k ==-1) a +='.', k = a.find('.');string s = a.substr(0, k)+ a.substr(k +1);while(s.size()&& s[0]=='0') s = s.substr(1), k --;if(s.empty()) k =0;if(s.size()> n) s = s.substr(0, n);else s +=string(n - s.size(),'0');return"0."+ s +"*10^"+to_string(k);}intmain(){int n;string a, b;cin >> n >> a >> b;a =change(a, n);b =change(b, n);if(a == b) cout <<"YES "<< a;else cout <<"NO "<< a <<' '<< b;}
#include<iostream>usingnamespace std;intmain(){string s;cin >> s;if(s[0]=='-') cout <<'-';int k = s.find('E');string a = s[1]+ s.substr(3, k -3);int b =stoi(s.substr(k +1));if(b <=0) cout <<"0."<<string(- b -1,'0');elseif(b < a.size()-1) a = a.substr(0, b +1)+'.'+ a.substr(b +1);else a +=string(b - a.size()+1,'0');cout << a;return0;}
#include<iostream>usingnamespace std;constint N =110;string s[N];intmain(){int n;cin >> n;getchar();for(int i =0; i < n; i ++)getline(cin, s[i]);for(int k = s[0].size(); k; k --){string sf = s[0].substr(s[0].size()- k);bool is_matched =true;for(int i =1; i < n; i ++)if(s[i].size()< k || s[i].substr(s[i].size()- k)!= sf){is_matched =false;break;}if(is_matched){cout << sf;return0;}}cout <<"nai";return0;}
1082 Read Number in Chinese (25 分)
題意 :
1084 Broken Keyboard (20 分)
題意 :The English letters must be capitalized英文字母必須大寫
#include<iostream>usingnamespace std;intmain(){string a, b;cin >> a >> b;bool st[200]={0};b +='#';for(int i =0, j =0; i < a.size(); i ++){char x =toupper(a[i]), y =toupper(b[j]);if(x == y) j ++;else{if(!st[x]) st[x]=true, cout << x;}}return0;}
#include<iostream>usingnamespace std;intmain(){int n;cin >> n;double sum =0;int cnt =0;while(n --){string num;cin >> num;double x;bool success =true;try{size_t idx;x =stof(num,&idx);if(idx < num.size()) success =false;}catch(...){success =false;}if(x <-1000|| x >1000) success =false;int k = num.find('.');if(k !=-1&& num.size()- k >3) success =false;if(success) cnt ++, sum += x;elseprintf("ERROR: %s is not a legal number\n", num.c_str());}if(cnt >1)printf("The average of %d numbers is %.2lf", cnt, sum / cnt);elseif(cnt ==1)printf("The average of 1 number is %.2lf", sum);elseprintf("The average of 0 numbers is Undefined");return0;}
#include<iostream>#include<unordered_set>usingnamespace std;constint N =1e3+10;string name[N];intmain(){int m, n, s;cin >> m >> n >> s;unordered_set<string> se;for(int i =1; i <= m; i ++) cin >> name[i];int k = s;while(k <= m){if(se.find(name[k])!= se.end()) k ++;else{cout << name[k]<< endl;se.insert(name[k]);k += n;}}if(se.empty()) cout <<"Keep going...";return0;}
#include<iostream>#include<cstring>#include<unordered_map>#include<algorithm>#include<vector>usingnamespace std;constint N =10010;int n, m;structPerson{string id;int grade;booloperator<(const Person &t)const{if(grade != t.grade)return grade > t.grade;return id < t.id;}}p[N];intmain(){cin >> n >> m;for(int i =0; i < n; i ++) cin >> p[i].id >> p[i].grade;for(int k =1; k <= m; k ++){string t, c;cin >> t >> c;printf("Case %d: %s %s\n", k, t.c_str(), c.c_str());if(t =="1"){vector<Person> persons;for(int i =0; i < n; i ++)if(p[i].id[0]== c[0])persons.push_back(p[i]);sort(persons.begin(), persons.end());if(persons.empty())puts("NA");elsefor(auto person : persons)printf("%s %d\n", person.id.c_str(), person.grade);}elseif(t =="2"){int cnt =0, sum =0;for(int i =0; i < n; i ++)if(p[i].id.substr(1,3)== c){cnt ++;sum += p[i].grade;}if(!cnt)puts("NA");elseprintf("%d %d\n", cnt, sum);}else{unordered_map<string,int> hash;for(int i =0; i < n; i ++)if(p[i].id.substr(4,6)== c)hash[p[i].id.substr(1,3)]++;vector<pair<int, string>> rooms;for(auto item : hash) rooms.push_back({-item.second, item.first});sort(rooms.begin(), rooms.end());if(rooms.empty())puts("NA");elsefor(auto room : rooms)printf("%s %d\n", room.second.c_str(),-room.first);}}return0;}