uva 刘汝佳第一个专题的简单题

来源:互联网 发布:网站php源代码在哪 编辑:程序博客网 时间:2024/06/05 17:40

10055

#include <algorithm>#include <iostream>#include <cstring>#include <string>#include <vector>#include <cstdio>#include <stack>#include <queue>#include <cmath>using namespace std;long long int n , m;long long int ans;int main(){    while(~scanf("%lld%lld%*c" , &n , &m)){        ans = abs(n-m);        printf("%lld\n",ans);    }    return 0;}


10071

#include <algorithm>#include <iostream>#include <cstring>#include <string>#include <vector>#include <cstdio>#include <stack>#include <queue>#include <cmath>#include <map>using namespace std;int ans;int v , t;int main(){    while(scanf("%d%d" , &v , &t) != EOF){        ans = t*2*v;        printf("%d\n" , ans);    }}

10300

#include <algorithm>#include <iostream>#include <cstring>#include <string>#include <vector>#include <cstdio>#include <stack>#include <queue>#include <cmath>using namespace std;int t , n;int ans;int main(){    int a , b , c;    scanf("%d%*c" , &t);    while(t--){        scanf("%d%*c" , &n);        ans = 0;        while(n--){            scanf("%d%d%d%*c" , &a , &b , &c);            ans += a*c;        }        printf("%d\n" , ans);    }}

458

#include <algorithm>#include <iostream>#include <cstring>#include <string>#include <vector>#include <cstdio>#include <stack>#include <queue>#include <cmath>using namespace std;#define MAXN 10000char ch[MAXN];int main(){    while(gets(ch)){        int len = strlen(ch);        for(int i = 0 ; i < len ; i++)            printf("%c" , ch[i]-7);        printf("\n");    }}

494

#include <algorithm>#include <iostream>#include <cstring>#include <string>#include <vector>#include <cstdio>#include <cctype>#include <stack>#include <queue>#include <cmath>using namespace std;#define MAXN 100000char ch[MAXN];int ans;int main(){    while(gets(ch)){        ans = 0;        for(int i = 0 ; i < strlen(ch) ; i++){            if(isalpha(ch[i]) && !isalpha(ch[i+1])) ans++;        }        printf("%d\n" , ans);    }    return 0;}

414

#include <algorithm>#include <iostream>#include <cstring>#include <string>#include <vector>#include <cstdio>#include <stack>#include <queue>#include <cmath>using namespace std;int main(){    //freopen("input.txt" , "r" , stdin);    char ch[26];//注意由于gets会把末尾的换行符变成空白字符,所以数组不能只开25大小,留一个位置给最后一个字符    int t , sum , ans , min ;    while(scanf("%d%*c" , &t) && t){        min = 999999999 ; ans = 0;        for(int i = 0 ; i < t ; i++){            gets(ch) ; sum = 0;            for(int i = 0 ; i < 25 ; i++){                if(ch[i] == ' ') sum++;            }            ans += sum;            if(sum < min) min = sum;        }        printf("%d\n" , ans-min*t);    }    return 0;}

490

//注意题目意思是输入n行字符串,然后换种方法输出//注意1 如果没有东西输出直接输空格  2 最后不用换行#include <algorithm>#include <iostream>#include <cstring>#include <string>#include <vector>#include <cstdio>#include <stack>#include <queue>#include <cmath>using namespace std;#define MAXN 110char str[MAXN];char ans[MAXN][MAXN];//存储输入的字符串int  cnt , len , max_len; int main(){    cnt = 0;    memset(ans , ' ' , sizeof(ans));//初始化为空格    while(gets(str)){        len = strlen(str);        if(strlen(str) > max_len)  max_len = len;//求出最大的长度        for(int i = 0 ; i < strlen(str) ; i++)            ans[cnt][i] = str[i];        cnt++;    }    //输出是从低向上输出    for(int j = 0 ; j < max_len ; j++){       for(int i = cnt-1 ; i >= 0 ; i--)          printf("%c" , ans[i][j]);       printf("\n");    }    return 0;}


445

#include <algorithm>#include <iostream>#include <cstring>#include <string>#include <vector>#include <cstdio>#include <stack>#include <queue>#include <cmath>using namespace std;char ch[500];int main(){    //freopen("input.txt" , "r" , stdin);    int num;    while(gets(ch)){//gets如果读入的一行的第一个字符是换行,那么ch[0] = NULL        for(int i = 0 ; i < strlen(ch) ; i++){             num = 0;            if(ch[i] == '!') printf("\n");            if(isdigit(ch[i])){               num = ch[i] - '0' ; i++;               while(isdigit(ch[i])){                     num += ch[i]-'0' ; i++;               }            }            while(num--){               if(ch[i] == 'b') printf(" ");               else printf("%c" , ch[i]);            }        }        printf("\n");    }    return 0;}

457

#include <algorithm>#include <iostream>#include <cstring>#include <string>#include <vector>#include <cstdio>#include <stack>#include <queue>#include <set>using namespace std;int cnt;int DNA[10];int dish[40];int tmp_dish[40];int main(){    //freopen("input.txt" , "r" , stdin);    while(scanf("%d" , &cnt) != EOF){        while(cnt--){            for(int i = 0 ; i < 10 ; i++) scanf("%d" , &DNA[i]);            memset(dish , 0 , sizeof(dish)) ; dish[19] = 1;            for(int i = 0 ; i < 50 ; i++){                memcpy(tmp_dish , dish , sizeof(dish));                for(int j = 0 ; j < 40 ; j++){                    if(dish[j] == 0) printf(" ");                    if(dish[j] == 1) printf(".");                    if(dish[j] == 2) printf("x");                    if(dish[j] == 3) printf("W");                }                printf("\n");                dish[0] = DNA[tmp_dish[0]+tmp_dish[1]];                for(int i = 1 ; i < 39 ; i++)                    dish[i] = DNA[tmp_dish[i-1]+tmp_dish[i]+tmp_dish[i+1]];                dish[39] = DNA[tmp_dish[38]+tmp_dish[39]];            }            if(cnt) printf("\n");        }    }    return 0;}

488

//输出注意: 1对于两个Case之间要打印一个空行  2 每一个Case里面也是每两个之间大于一个空行,最后一个不用#include <algorithm>#include <iostream>#include <cstring>#include <string>#include <vector>#include <cstdio>#include <stack>#include <queue>#include <cmath>using namespace std;int t , f , h;int main(){    //freopen("input.txt" , "r" , stdin);    scanf("%d" , &t);    while(t--){        scanf("%d%d" , &f , &h);        while(h--){            for(int i = 1 ; i <= f ; i++){                for(int j = 1 ; j <= i ; j++) printf("%d" , i);                printf("\n");            }            for(int i = f-1 ; i >= 1 ; i--){                for(int j = 1 ; j <= i ; j++) printf("%d" , i);                printf("\n");            }            if(h) printf("\n");        }        if(t) printf("\n");    }    return 0;}

694

//TLE到死啊,看了别人的代码,才知道这个鸟题中间运算值竟然会超int,所以改了long才A#include <algorithm>#include <iostream>#include <cstring>#include <string>#include <vector>#include <cstdio>#include <stack>#include <queue>#include <cmath>using namespace std;long ans , A , l , cnt;int main(){    //freopen("input.txt" , "r" , stdin);    cnt = 1;    while(scanf("%ld%ld" , &A , &l)){        if(A < 0 && l < 0) break;        long tmp_A = A ; ans = 0;        while(1){            if(A == 1) {ans++ ; break;}            if(A > l) break;            ans++;            if(A%2 == 0) A /= 2;            else A = 3*A + 1;        }        printf("Case %ld: A = %ld, limit = %ld, number of terms = %ld\n" , cnt++ , tmp_A , l , ans);    }    return 0;}

489

 /*1 给定两个字符串,第一个串是用来匹配的,从第二个串的第一个字符开始匹配,如果第二个串中的字符在第一个串出现,则表示猜中了,第一个串中的相同的那个字符都算被猜中;如果没有出现则表示猜错,同样的猜错只算一次。2在整个匹配的过程中,如果在还没猜错7次之前,第一个串中所有的字符都被猜完了, 则输出“You win.”,如果你还没全部猜完的时候就已经猜错7次,则输出“You lose.”。如果整个匹配过程结束后,你没赢也没输,则输出“You chickened out.”。*/#include <algorithm>#include <iostream>#include <cstring>#include <string>#include <vector>#include <cstdio>#include <stack>#include <queue>#include <set>using namespace std;#define MAXN 1010int n;char ch[MAXN];int vis[26];set<char>s;int solve(){    int wrong_cnt = 0;    int len = s.size();    memset(vis , 0 , sizeof(vis));    set<char>::iterator it;    for(int i = 0 ; i < strlen(ch) ; i++){        if(!vis[ch[i]-'a']){            if(s.size() == 0){                if(wrong_cnt >= 7) return 0;                else return 1;            }             if(wrong_cnt >= 7) return 0;            it = s.find(ch[i]);            if(it != s.end()) s.erase(it);            if(it == s.end()) wrong_cnt++ ;            vis[ch[i]-'a'] = 1;        }    }    if(s.size() && wrong_cnt < 7) return -1;    if(!s.size() && wrong_cnt < 7) return 1;    if(wrong_cnt >= 7) return 0;}int main(){    //freopen("input.txt" , "r" , stdin);    int flag;    while(scanf("%d" , &n)){        if(n == -1) break;        getchar() ; gets(ch) ; s.clear();        for(int i = 0 ; i < strlen(ch) ; i++)            s.insert(ch[i]);        gets(ch) ;        printf("Round %d\n" , n) ; flag = solve();        if(flag == 0) printf("You lose.\n");        if(flag == 1) printf("You win.\n");        if(flag == -1) printf("You chickened out.\n");    }    return 0;}